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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package packet
import (
"bytes"
"fmt"
)
type Msg interface {
MsgType() uint8
}
const (
MinLen = 6
RouteMonitoringType = 0
StatisticsReportType = 1
PeerDownNotificationType = 2
PeerUpNotificationType = 3
InitiationMessageType = 4
TerminationMessageType = 5
RouteMirroringMessageType = 6
BGPMessage = 0
BGPInformation = 1
ErroredPDU = 0
MessageLost = 1
)
// Decode decodes a BMP message
func Decode(msg []byte) (Msg, error) {
buf := bytes.NewBuffer(msg)
ch, err := decodeCommonHeader(buf)
if err != nil {
return nil, fmt.Errorf("Unable to decode common header: %v", err)
}
if ch.Version != 3 {
return nil, fmt.Errorf("Unsupported BMP version: %d", ch.Version)
}
switch ch.MsgType {
case RouteMonitoringType:
case StatisticsReportType:
sr, err := decodeStatsReport(buf, ch)
if err != nil {
return nil, fmt.Errorf("Unable to decode stats report: %v", err)
}
return sr, nil
case PeerDownNotificationType:
pd, err := decodePeerUpNotification(buf, ch)
if err != nil {
return nil, fmt.Errorf("Unable to decode peer down notification: %v", err)
}
return pd, nil
case PeerUpNotificationType:
pu, err := decodePeerUpNotification(buf, ch)
if err != nil {
return nil, fmt.Errorf("Unable to decode peer up notification: %v", err)
}
return pu, nil
case InitiationMessageType:
im, err := decodeInitiationMessage(buf, ch)
if err != nil {
return nil, fmt.Errorf("Unable to decode initiation message: %v", err)
}
return im, nil
case TerminationMessageType:
tm, err := decodeTerminationMessage(buf, ch)
if err != nil {
return nil, fmt.Errorf("Unable to decide termination message: %v", err)
}
return tm, nil
case RouteMirroringMessageType:
default:
return nil, fmt.Errorf("Unexpected message type: %d", ch.MsgType)
}
return nil, fmt.Errorf("Unexpected message type: %d", ch.MsgType)
}