-
Notifications
You must be signed in to change notification settings - Fork 44
/
parameters.go
75 lines (59 loc) · 1.31 KB
/
parameters.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
71
72
73
74
75
package packet
import (
"bytes"
"github.com/bio-routing/tflow2/convert"
)
type Serializable interface {
serialize(*bytes.Buffer)
}
type OptParam struct {
Type uint8
Length uint8
Value Serializable
}
type Capabilities []Capability
type Capability struct {
Code uint8
Length uint8
Value Serializable
}
func (c Capabilities) serialize(buf *bytes.Buffer) {
tmpBuf := bytes.NewBuffer(make([]byte, 0))
for _, cap := range c {
cap.serialize(tmpBuf)
}
buf.Write(tmpBuf.Bytes())
}
func (c Capability) serialize(buf *bytes.Buffer) {
tmpBuf := bytes.NewBuffer(make([]byte, 0))
c.Value.serialize(tmpBuf)
payload := tmpBuf.Bytes()
buf.WriteByte(c.Code)
buf.WriteByte(uint8(len(payload)))
buf.Write(payload)
}
type AddPathCapability struct {
AFI uint16
SAFI uint8
SendReceive uint8
}
func (a AddPathCapability) serialize(buf *bytes.Buffer) {
buf.Write(convert.Uint16Byte(a.AFI))
buf.WriteByte(a.SAFI)
buf.WriteByte(a.SendReceive)
}
type ASN4Capability struct {
ASN4 uint32
}
func (a ASN4Capability) serialize(buf *bytes.Buffer) {
buf.Write(convert.Uint32Byte(a.ASN4))
}
type MultiProtocolCapability struct {
AFI uint16
SAFI uint8
}
func (a MultiProtocolCapability) serialize(buf *bytes.Buffer) {
buf.Write(convert.Uint16Byte(a.AFI))
buf.WriteByte(0) // RESERVED
buf.WriteByte(a.SAFI)
}