go-bgp

a collection of golang BGP tools to monitor, archive and serve
git clone git://git.2f30.org/go-bgp.git
Log | Files | Refs | README

commit aefacb21bbe6742cd74196cbcc13cb9bfc5e38ee
parent 71416f5afbd9e17436721ebdb1ceea66fbab3f3d
Author: dsp <dsp@2f30.org>
Date:   Fri Feb 20 21:28:11 -0700

implemented necessary structs for MrtTableDumpv2. Added the new Mrter interface that will take the place of MrtSubTyper. Change the name of the MrtMsg Msg field to Msg instead of BGPMsg,since this is the actual MRT message

Diffstat:
mrt/mrt.go | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
mrt/mrt_test.go | 28++++++++++++++--------------
2 files changed, 71 insertions(+), 16 deletions(-)
diff --git a/mrt/mrt.go b/mrt/mrt.go @@ -25,8 +25,8 @@ type MrtHdr struct { type parsefunc func([]byte) MrtSubTyper type MrtMsg struct { - Hdr MrtHdr - BGPMsg []byte + Hdr MrtHdr + Msg []byte } type MrtSubTyper interface { @@ -34,6 +34,14 @@ type MrtSubTyper interface { String() string } +type Mrter interface { + Hdr() MrtHdr + Type() uint16 + SubType() uint16 + Len() uint32 + Msg() []byte +} + type MrtOSPFHdr struct { otype uint16 RemoteIP uint32 @@ -255,6 +263,44 @@ func (m *MrtTableDumpV1Hdr) String() string { return "TableDumpV1Hdr" } +type MrtTableDumpV2PIHdr struct { + CollectorID uint32 + ViewNameLen []byte + PeerCount uint16 + Peers []MrtTableDumpV2PeerEntry +} + +type MrtTableDumpV2PeerEntry struct { + PeerType uint8 + PeerBGPID uint32 + PeerIP []byte + PeerAS []byte +} + +type MrtTableDumpV2RIBDef struct { + SequenceNum uint32 + PrefixLen uint8 + Prefix uint32 + EntryCount uint16 + Entries []MrtTableDumpV2RIBEntry +} + +type MrtTableDumpV2RIBGen struct { + SequenceNum uint32 + AFI uint16 + SAFI uint8 + NLRI []byte + EntryCount uint16 + Entries []MrtTableDumpV2RIBEntry +} + +type MrtTableDumpV2RIBEntry struct { + PeerIndex uint16 + OrigTime uint32 + AttrLen uint16 + BGPAttrs []byte +} + type MrtFile struct { file io.Reader entries uint32 @@ -305,6 +351,15 @@ const ( OSPF_LSA_UPDATE ) +const ( + PEER_INDEX_TABLE = iota + 1 + RIB_IPV4_UNICAST + RIB_IPV4_MULTICAST + RIB_IPV6_UNICAST + RIB_IPV6_MULTICAST + RIB_GENERIC +) + func NewMrtHdr(b []byte) (ret MrtHdr, err error) { buf := bytes.NewReader(b) err = binary.Read(buf, binary.BigEndian, &ret) diff --git a/mrt/mrt_test.go b/mrt/mrt_test.go @@ -38,33 +38,33 @@ func TestMrtPFunc(t *testing.T) { //binbuf := new(bytes.Buffer) mrt1 := &MrtMsg{ Hdr: MrtHdr{1, tt1, ts1, 10}, - BGPMsg: tbuf, + Msg: tbuf, } mrt2 := &MrtMsg{ Hdr: MrtHdr{1, tt2, ts2, 10}, - BGPMsg: tbuf, + Msg: tbuf, } mrt3 := &MrtMsg{ Hdr: MrtHdr{1, tt3, ts3, 10}, - BGPMsg: tbuf, + Msg: tbuf, } mrt4 := &MrtMsg{ Hdr: MrtHdr{1, tt4, ts4, 10}, - BGPMsg: tbuf, + Msg: tbuf, } fmt.Println("trying to parse informational message") if tf, ok = mrt1.PFunc(); !ok { t.Fatal("tf should be non nil") } - hdr := tf(mrt1.BGPMsg) + hdr := tf(mrt1.Msg) fmt.Printf("type is :%s\n", hdr.Type()) fmt.Println("trying to parse informational message with opt string") - mrt1.BGPMsg = []byte{'f', 'o', 'o', ' ', 's', 't', 'r'} + mrt1.Msg = []byte{'f', 'o', 'o', ' ', 's', 't', 'r'} mrt1.Hdr.Mrt_type = tt2 if tf, ok = mrt1.PFunc(); !ok { t.Fatal("tf should be non nil") } - hdr = tf(mrt1.BGPMsg) + hdr = tf(mrt1.Msg) fmt.Printf("type is :%s\n", hdr.Type()) fmt.Println("trying to parse malformed informational message") if tf, ok = mrt2.PFunc(); ok { @@ -76,16 +76,16 @@ func TestMrtPFunc(t *testing.T) { } fmt.Println("trying to parse OSPF message") //first call to littleendian to come to hostbyteorder and then switch to big - binary.BigEndian.PutUint32(mrt4.BGPMsg[:4], binary.LittleEndian.Uint32(net.IPv4(1, 2, 3, 4).To4())) - binary.BigEndian.PutUint32(mrt4.BGPMsg[4:], binary.LittleEndian.Uint32(net.IPv4(5, 6, 7, 8).To4())) + binary.BigEndian.PutUint32(mrt4.Msg[:4], binary.LittleEndian.Uint32(net.IPv4(1, 2, 3, 4).To4())) + binary.BigEndian.PutUint32(mrt4.Msg[4:], binary.LittleEndian.Uint32(net.IPv4(5, 6, 7, 8).To4())) //binary.Write(binbuf, binary.BigEndian, net.IPv4allsys.To4()) - //mrt4.BGPMsg = make([]byte,8) - //mrt4.BGPMsg = binbuf.Bytes() + //mrt4.Msg = make([]byte,8) + //mrt4.Msg = binbuf.Bytes() //copy(mrt4.BGPMsg,binbuf.Bytes()) if tf, ok = mrt4.PFunc(); !ok { t.Fatal("this shouldn't fail") } - hdr = tf(mrt4.BGPMsg) + hdr = tf(mrt4.Msg) fmt.Printf("type is :%s .String representation: %s\n", hdr.Type(), hdr) } @@ -106,9 +106,9 @@ func TestScan(t *testing.T) { t.Logf("terminating from 0 mrt len") return } - mrtmsg := MrtMsg{Hdr: h, BGPMsg: dat[MrtHdr_size:]} + mrtmsg := MrtMsg{Hdr: h, Msg: dat[MrtHdr_size:]} if tf, ok := mrtmsg.PFunc(); ok { - tf(mrtmsg.BGPMsg) + tf(mrtmsg.Msg) } } if err := mrtscanner.Err(); err != nil {