Newer
Older
package packet
import (
"bytes"
"github.com/bio-routing/bio-rd/util/decoder"
"github.com/bio-routing/tflow2/convert"
)
const (
// PerPeerHeaderLen is the length of a per peer header
PerPeerHeaderLen = 38
)
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
// PerPeerHeader represents a BMP per peer header
type PerPeerHeader struct {
PeerType uint8
PeerFlags uint8
PeerDistinguisher uint32
PeerAddress [16]byte
PeerAS uint32
PeerBGPID uint32
Timestamp uint32
TimestampMicroSeconds uint32
}
// Serialize serializes a per peer header
func (p *PerPeerHeader) Serialize(buf *bytes.Buffer) {
buf.WriteByte(p.PeerType)
buf.WriteByte(p.PeerFlags)
buf.Write(convert.Uint32Byte(p.PeerDistinguisher))
buf.Write(p.PeerAddress[:])
buf.Write(convert.Uint32Byte(p.PeerAS))
buf.Write(convert.Uint32Byte(p.PeerBGPID))
buf.Write(convert.Uint32Byte(p.Timestamp))
buf.Write(convert.Uint32Byte(p.TimestampMicroSeconds))
}
func decodePerPeerHeader(buf *bytes.Buffer) (*PerPeerHeader, error) {
p := &PerPeerHeader{}
fields := []interface{}{
&p.PeerType,
&p.PeerFlags,
&p.PeerDistinguisher,
&p.PeerAddress,
&p.PeerAS,
&p.PeerBGPID,
&p.Timestamp,
&p.TimestampMicroSeconds,
}
err := decoder.Decode(buf, fields)
if err != nil {
return p, err
}
return p, nil
}