summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-07-22 13:24:31 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-07-22 14:49:46 +0900
commita4501ccc3f680de0a9f9cc8621256d71d3679478 (patch)
tree1ab8e04fb4c6c39f512be1e9f76c26c78a127ac7 /packet
parent3409f6a5443cf0d6cf0d318feba845f237cd14ba (diff)
mrt: support mrt dump
$ gobgp mrt dump 10 -o ./dump Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r--packet/mrt.go41
1 files changed, 38 insertions, 3 deletions
diff --git a/packet/mrt.go b/packet/mrt.go
index f31013ec..5e4f2597 100644
--- a/packet/mrt.go
+++ b/packet/mrt.go
@@ -144,6 +144,30 @@ type MRTMessage struct {
Body Body
}
+func (m *MRTMessage) Serialize() ([]byte, error) {
+ buf, err := m.Body.Serialize()
+ if err != nil {
+ return nil, err
+ }
+ m.Header.Len = uint32(len(buf))
+ bbuf, err := m.Header.Serialize()
+ if err != nil {
+ return nil, err
+ }
+ return append(bbuf, buf...), nil
+}
+
+func NewMRTMessage(timestamp uint32, t MRTType, subtype MRTSubTyper, body Body) (*MRTMessage, error) {
+ header, err := NewMRTHeader(timestamp, t, subtype, 0)
+ if err != nil {
+ return nil, err
+ }
+ return &MRTMessage{
+ Header: *header,
+ Body: body,
+ }, nil
+}
+
type Body interface {
DecodeFromBytes([]byte) error
Serialize() ([]byte, error)
@@ -201,9 +225,6 @@ func (p *Peer) Serialize() ([]byte, error) {
var bbuf []byte
buf := make([]byte, 5)
buf[0] = uint8(p.Type)
- if p.BgpId.To4() == nil {
- return nil, fmt.Errorf("invalid BGP ID")
- }
copy(buf[1:], p.BgpId.To4())
if p.Type&1 > 0 {
buf = append(buf, p.IpAddress.To16()...)
@@ -354,6 +375,16 @@ func (e *RibEntry) Serialize() ([]byte, error) {
totalLen := 0
binary.BigEndian.PutUint16(buf[6:], uint16(totalLen))
for _, pattr := range e.PathAttributes {
+ // TODO special modification is needed for MP_REACH_NLRI
+ // but also Quagga doesn't implement this.
+ //
+ // RFC 6396 4.3.4
+ // There is one exception to the encoding of BGP attributes for the BGP
+ // MP_REACH_NLRI attribute (BGP Type Code 14).
+ // Since the AFI, SAFI, and NLRI information is already encoded
+ // in the RIB Entry Header or RIB_GENERIC Entry Header,
+ // only the Next Hop Address Length and Next Hop Address fields are included.
+
bbuf, err := pattr.Serialize()
if err != nil {
return nil, err
@@ -373,6 +404,10 @@ func NewRibEntry(index uint16, time uint32, pathattrs []PathAttributeInterface)
}
}
+func (e *RibEntry) String() string {
+ return fmt.Sprintf("RIB_ENTRY: PeerIndex [%d] OriginatedTime [%d] PathAttrs [%v]", e.PeerIndex, e.OriginatedTime, e.PathAttributes)
+}
+
type Rib struct {
SequenceNumber uint32
Prefix AddrPrefixInterface