summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gomrt/main.go20
-rw-r--r--packet/mrt.go (renamed from gomrt/packet/mrt.go)57
-rw-r--r--packet/mrt_test.go (renamed from gomrt/packet/mrt_test.go)49
3 files changed, 62 insertions, 64 deletions
diff --git a/gomrt/main.go b/gomrt/main.go
index 86fad3a2..aeca76af 100644
--- a/gomrt/main.go
+++ b/gomrt/main.go
@@ -18,7 +18,7 @@ package main
import (
"fmt"
"github.com/osrg/gobgp/api"
- "github.com/osrg/gobgp/gomrt/packet"
+ "github.com/osrg/gobgp/packet"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc"
@@ -77,7 +77,7 @@ func main() {
go func() {
for {
- buf := make([]byte, mrt.MRT_COMMON_HEADER_LEN)
+ buf := make([]byte, bgp.MRT_COMMON_HEADER_LEN)
_, err := file.Read(buf)
if err == io.EOF {
break
@@ -86,7 +86,7 @@ func main() {
os.Exit(1)
}
- h := &mrt.MRTHeader{}
+ h := &bgp.MRTHeader{}
err = h.DecodeFromBytes(buf)
if err != nil {
fmt.Println("failed to parse")
@@ -100,27 +100,27 @@ func main() {
os.Exit(1)
}
- msg, err := mrt.ParseMRTBody(h, buf)
+ msg, err := bgp.ParseMRTBody(h, buf)
if err != nil {
fmt.Println("failed to parse:", err)
os.Exit(1)
}
- if msg.Header.Type == mrt.TABLE_DUMPv2 {
- subType := mrt.MRTSubTypeTableDumpv2(msg.Header.SubType)
+ if msg.Header.Type == bgp.TABLE_DUMPv2 {
+ subType := bgp.MRTSubTypeTableDumpv2(msg.Header.SubType)
var af *api.AddressFamily
switch subType {
- case mrt.PEER_INDEX_TABLE:
+ case bgp.PEER_INDEX_TABLE:
continue
- case mrt.RIB_IPV4_UNICAST:
+ case bgp.RIB_IPV4_UNICAST:
af = api.AF_IPV4_UC
- case mrt.RIB_IPV6_UNICAST:
+ case bgp.RIB_IPV6_UNICAST:
af = api.AF_IPV6_UC
default:
fmt.Println("unsupported subType:", subType)
os.Exit(1)
}
- rib := msg.Body.(*mrt.Rib)
+ rib := msg.Body.(*bgp.Rib)
prefix := rib.Prefix.String()
path := &api.Path{}
path.Nlri = &api.Nlri{
diff --git a/gomrt/packet/mrt.go b/packet/mrt.go
index a9339767..f31013ec 100644
--- a/gomrt/packet/mrt.go
+++ b/packet/mrt.go
@@ -13,13 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package mrt
+package bgp
import (
"bytes"
"encoding/binary"
"fmt"
- "github.com/osrg/gobgp/packet"
"math"
"net"
)
@@ -317,7 +316,7 @@ func (t *PeerIndexTable) String() string {
type RibEntry struct {
PeerIndex uint16
OriginatedTime uint32
- PathAttributes []bgp.PathAttributeInterface
+ PathAttributes []PathAttributeInterface
}
func (e *RibEntry) DecodeFromBytes(data []byte) ([]byte, error) {
@@ -330,7 +329,7 @@ func (e *RibEntry) DecodeFromBytes(data []byte) ([]byte, error) {
totalLen := binary.BigEndian.Uint16(data[6:8])
data = data[8:]
for attrLen := totalLen; attrLen > 0; {
- p, err := bgp.GetPathAttribute(data)
+ p, err := GetPathAttribute(data)
if err != nil {
return nil, err
}
@@ -366,7 +365,7 @@ func (e *RibEntry) Serialize() ([]byte, error) {
return buf, nil
}
-func NewRibEntry(index uint16, time uint32, pathattrs []bgp.PathAttributeInterface) *RibEntry {
+func NewRibEntry(index uint16, time uint32, pathattrs []PathAttributeInterface) *RibEntry {
return &RibEntry{
PeerIndex: index,
OriginatedTime: time,
@@ -376,9 +375,9 @@ func NewRibEntry(index uint16, time uint32, pathattrs []bgp.PathAttributeInterfa
type Rib struct {
SequenceNumber uint32
- Prefix bgp.AddrPrefixInterface
+ Prefix AddrPrefixInterface
Entries []*RibEntry
- RouteFamily bgp.RouteFamily
+ RouteFamily RouteFamily
}
func (u *Rib) DecodeFromBytes(data []byte) error {
@@ -387,13 +386,13 @@ func (u *Rib) DecodeFromBytes(data []byte) error {
}
u.SequenceNumber = binary.BigEndian.Uint32(data[:4])
data = data[4:]
- afi, safi := bgp.RouteFamilyToAfiSafi(u.RouteFamily)
+ afi, safi := RouteFamilyToAfiSafi(u.RouteFamily)
if afi == 0 && safi == 0 {
afi = binary.BigEndian.Uint16(data[:2])
safi = data[2]
data = data[3:]
}
- prefix, err := bgp.NewPrefixFromRouteFamily(afi, safi)
+ prefix, err := NewPrefixFromRouteFamily(afi, safi)
if err != nil {
return err
}
@@ -420,9 +419,9 @@ func (u *Rib) DecodeFromBytes(data []byte) error {
func (u *Rib) Serialize() ([]byte, error) {
buf := make([]byte, 4)
binary.BigEndian.PutUint32(buf, u.SequenceNumber)
- rf := bgp.AfiSafiToRouteFamily(u.Prefix.AFI(), u.Prefix.SAFI())
+ rf := AfiSafiToRouteFamily(u.Prefix.AFI(), u.Prefix.SAFI())
switch rf {
- case bgp.RF_IPv4_UC, bgp.RF_IPv4_MC, bgp.RF_IPv6_UC, bgp.RF_IPv6_MC:
+ case RF_IPv4_UC, RF_IPv4_MC, RF_IPv6_UC, RF_IPv6_MC:
default:
bbuf := make([]byte, 0, 2)
binary.BigEndian.PutUint16(bbuf, u.Prefix.AFI())
@@ -449,8 +448,8 @@ func (u *Rib) Serialize() ([]byte, error) {
return buf, nil
}
-func NewRib(seq uint32, prefix bgp.AddrPrefixInterface, entries []*RibEntry) *Rib {
- rf := bgp.AfiSafiToRouteFamily(prefix.AFI(), prefix.SAFI())
+func NewRib(seq uint32, prefix AddrPrefixInterface, entries []*RibEntry) *Rib {
+ rf := AfiSafiToRouteFamily(prefix.AFI(), prefix.SAFI())
return &Rib{
SequenceNumber: seq,
Prefix: prefix,
@@ -492,11 +491,11 @@ func (m *BGP4MPHeader) decodeFromBytes(data []byte) ([]byte, error) {
m.InterfaceIndex = binary.BigEndian.Uint16(data[:2])
m.AddressFamily = binary.BigEndian.Uint16(data[2:4])
switch m.AddressFamily {
- case bgp.AFI_IP:
+ case AFI_IP:
m.PeerIpAddress = net.IP(data[4:8]).To4()
m.LocalIpAddress = net.IP(data[8:12]).To4()
data = data[12:]
- case bgp.AFI_IP6:
+ case AFI_IP6:
m.PeerIpAddress = net.IP(data[4:20])
m.LocalIpAddress = net.IP(data[20:36])
data = data[36:]
@@ -519,11 +518,11 @@ func (m *BGP4MPHeader) serialize() ([]byte, error) {
}
var bbuf []byte
switch m.AddressFamily {
- case bgp.AFI_IP:
+ case AFI_IP:
bbuf = make([]byte, 8)
copy(bbuf, m.PeerIpAddress.To4())
copy(bbuf[4:], m.LocalIpAddress.To4())
- case bgp.AFI_IP6:
+ case AFI_IP6:
bbuf = make([]byte, 32)
copy(bbuf, m.PeerIpAddress)
copy(bbuf[16:], m.LocalIpAddress)
@@ -538,12 +537,12 @@ func newBGP4MPHeader(peeras, localas uint32, intfindex uint16, peerip, localip s
paddr := net.ParseIP(peerip).To4()
laddr := net.ParseIP(localip).To4()
if paddr != nil && laddr != nil {
- af = bgp.AFI_IP
+ af = AFI_IP
} else {
paddr = net.ParseIP(peerip).To16()
laddr = net.ParseIP(localip).To16()
if paddr != nil && laddr != nil {
- af = bgp.AFI_IP6
+ af = AFI_IP6
} else {
return nil, fmt.Errorf("Peer IP Address and Local IP Address must have the same address family")
}
@@ -601,7 +600,7 @@ func NewBGP4MPStateChange(peeras, localas uint32, intfindex uint16, peerip, loca
type BGP4MPMessage struct {
*BGP4MPHeader
- BGPMessage *bgp.BGPMessage
+ BGPMessage *BGPMessage
isLocal bool
}
@@ -611,11 +610,11 @@ func (m *BGP4MPMessage) DecodeFromBytes(data []byte) error {
return err
}
- if len(rest) < bgp.BGP_HEADER_LENGTH {
+ if len(rest) < BGP_HEADER_LENGTH {
return fmt.Errorf("Not all BGP4MPMessageAS4 bytes available")
}
- msg, err := bgp.ParseBGPMessage(rest)
+ msg, err := ParseBGPMessage(rest)
if err != nil {
return err
}
@@ -635,7 +634,7 @@ func (m *BGP4MPMessage) Serialize() ([]byte, error) {
return append(buf, bbuf...), nil
}
-func NewBGP4MPMessage(peeras, localas uint32, intfindex uint16, peerip, localip string, isAS4 bool, msg *bgp.BGPMessage) *BGP4MPMessage {
+func NewBGP4MPMessage(peeras, localas uint32, intfindex uint16, peerip, localip string, isAS4 bool, msg *BGPMessage) *BGP4MPMessage {
header, _ := newBGP4MPHeader(peeras, localas, intfindex, peerip, localip, isAS4)
return &BGP4MPMessage{
BGP4MPHeader: header,
@@ -643,7 +642,7 @@ func NewBGP4MPMessage(peeras, localas uint32, intfindex uint16, peerip, localip
}
}
-func NewBGP4MPMessageLocal(peeras, localas uint32, intfindex uint16, peerip, localip string, isAS4 bool, msg *bgp.BGPMessage) *BGP4MPMessage {
+func NewBGP4MPMessageLocal(peeras, localas uint32, intfindex uint16, peerip, localip string, isAS4 bool, msg *BGPMessage) *BGP4MPMessage {
header, _ := newBGP4MPHeader(peeras, localas, intfindex, peerip, localip, isAS4)
return &BGP4MPMessage{
BGP4MPHeader: header,
@@ -671,18 +670,18 @@ func ParseMRTBody(h *MRTHeader, data []byte) (*MRTMessage, error) {
switch h.Type {
case TABLE_DUMPv2:
subType := MRTSubTypeTableDumpv2(h.SubType)
- rf := bgp.RouteFamily(0)
+ rf := RouteFamily(0)
switch subType {
case PEER_INDEX_TABLE:
msg.Body = &PeerIndexTable{}
case RIB_IPV4_UNICAST:
- rf = bgp.RF_IPv4_UC
+ rf = RF_IPv4_UC
case RIB_IPV4_MULTICAST:
- rf = bgp.RF_IPv4_MC
+ rf = RF_IPv4_MC
case RIB_IPV6_UNICAST:
- rf = bgp.RF_IPv6_UC
+ rf = RF_IPv6_UC
case RIB_IPV6_MULTICAST:
- rf = bgp.RF_IPv6_MC
+ rf = RF_IPv6_MC
case RIB_GENERIC:
default:
return nil, fmt.Errorf("unsupported table dumpv2 subtype: %s\n", subType)
diff --git a/gomrt/packet/mrt_test.go b/packet/mrt_test.go
index e518fd84..7aa073c4 100644
--- a/gomrt/packet/mrt_test.go
+++ b/packet/mrt_test.go
@@ -13,10 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package mrt
+package bgp
import (
- "github.com/osrg/gobgp/packet"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
@@ -87,18 +86,18 @@ func TestMrtPeerIndexTable(t *testing.T) {
}
func TestMrtRibEntry(t *testing.T) {
- aspath1 := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(2, []uint16{1000}),
- bgp.NewAsPathParam(1, []uint16{1001, 1002}),
- bgp.NewAsPathParam(2, []uint16{1003, 1004}),
+ aspath1 := []AsPathParamInterface{
+ NewAsPathParam(2, []uint16{1000}),
+ NewAsPathParam(1, []uint16{1001, 1002}),
+ NewAsPathParam(2, []uint16{1003, 1004}),
}
- p := []bgp.PathAttributeInterface{
- bgp.NewPathAttributeOrigin(3),
- bgp.NewPathAttributeAsPath(aspath1),
- bgp.NewPathAttributeNextHop("129.1.1.2"),
- bgp.NewPathAttributeMultiExitDisc(1 << 20),
- bgp.NewPathAttributeLocalPref(1 << 22),
+ p := []PathAttributeInterface{
+ NewPathAttributeOrigin(3),
+ NewPathAttributeAsPath(aspath1),
+ NewPathAttributeNextHop("129.1.1.2"),
+ NewPathAttributeMultiExitDisc(1 << 20),
+ NewPathAttributeLocalPref(1 << 22),
}
e1 := NewRibEntry(1, uint32(time.Now().Unix()), p)
@@ -117,31 +116,31 @@ func TestMrtRibEntry(t *testing.T) {
}
func TestMrtRib(t *testing.T) {
- aspath1 := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(2, []uint16{1000}),
- bgp.NewAsPathParam(1, []uint16{1001, 1002}),
- bgp.NewAsPathParam(2, []uint16{1003, 1004}),
+ aspath1 := []AsPathParamInterface{
+ NewAsPathParam(2, []uint16{1000}),
+ NewAsPathParam(1, []uint16{1001, 1002}),
+ NewAsPathParam(2, []uint16{1003, 1004}),
}
- p := []bgp.PathAttributeInterface{
- bgp.NewPathAttributeOrigin(3),
- bgp.NewPathAttributeAsPath(aspath1),
- bgp.NewPathAttributeNextHop("129.1.1.2"),
- bgp.NewPathAttributeMultiExitDisc(1 << 20),
- bgp.NewPathAttributeLocalPref(1 << 22),
+ p := []PathAttributeInterface{
+ NewPathAttributeOrigin(3),
+ NewPathAttributeAsPath(aspath1),
+ NewPathAttributeNextHop("129.1.1.2"),
+ NewPathAttributeMultiExitDisc(1 << 20),
+ NewPathAttributeLocalPref(1 << 22),
}
e1 := NewRibEntry(1, uint32(time.Now().Unix()), p)
e2 := NewRibEntry(2, uint32(time.Now().Unix()), p)
e3 := NewRibEntry(3, uint32(time.Now().Unix()), p)
- r1 := NewRib(1, bgp.NewIPAddrPrefix(24, "192.168.0.0"), []*RibEntry{e1, e2, e3})
+ r1 := NewRib(1, NewIPAddrPrefix(24, "192.168.0.0"), []*RibEntry{e1, e2, e3})
b1, err := r1.Serialize()
if err != nil {
t.Fatal(err)
}
r2 := &Rib{
- RouteFamily: bgp.RF_IPv4_UC,
+ RouteFamily: RF_IPv4_UC,
}
err = r2.DecodeFromBytes(b1)
if err != nil {
@@ -169,7 +168,7 @@ func TestMrtBgp4mpStateChange(t *testing.T) {
}
func TestMrtBgp4mpMessage(t *testing.T) {
- msg := bgp.NewBGPKeepAliveMessage()
+ msg := NewBGPKeepAliveMessage()
m1 := NewBGP4MPMessage(65000, 65001, 1, "192.168.0.1", "192.168.0.2", false, msg)
b1, err := m1.Serialize()
if err != nil {