From 99336372ab2ae8a3b61af63abbcbd70223a1dfe1 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Mon, 29 May 2017 11:09:40 +0900 Subject: packet/mrt: BGP Additional Path Extensions (RFC8050) This patch enables to decode/encode MRT format with BGP Additional Path Extensions which described in RFC8050. Signed-off-by: IWASE Yusuke --- packet/mrt/mrt_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'packet/mrt/mrt_test.go') diff --git a/packet/mrt/mrt_test.go b/packet/mrt/mrt_test.go index 634d69ae..1b5978b0 100644 --- a/packet/mrt/mrt_test.go +++ b/packet/mrt/mrt_test.go @@ -114,7 +114,7 @@ func TestMrtRibEntry(t *testing.T) { bgp.NewPathAttributeLocalPref(1 << 22), } - e1 := NewRibEntry(1, uint32(time.Now().Unix()), p) + e1 := NewRibEntry(1, uint32(time.Now().Unix()), 0, p) b1, err := e1.Serialize() if err != nil { t.Fatal(err) @@ -129,6 +129,35 @@ func TestMrtRibEntry(t *testing.T) { assert.Equal(t, reflect.DeepEqual(e1, e2), true) } +func TestMrtRibEntryWithAddPath(t *testing.T) { + aspath1 := []bgp.AsPathParamInterface{ + bgp.NewAsPathParam(2, []uint16{1000}), + bgp.NewAsPathParam(1, []uint16{1001, 1002}), + bgp.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), + } + e1 := NewRibEntry(1, uint32(time.Now().Unix()), 200, p) + b1, err := e1.Serialize() + if err != nil { + t.Fatal(err) + } + + e2 := &RibEntry{isAddPath: true} + rest, err := e2.DecodeFromBytes(b1) + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(rest), 0) + assert.Equal(t, reflect.DeepEqual(e1, e2), true) +} + func TestMrtRib(t *testing.T) { aspath1 := []bgp.AsPathParamInterface{ bgp.NewAsPathParam(2, []uint16{1000}), @@ -144,9 +173,43 @@ func TestMrtRib(t *testing.T) { bgp.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) + e1 := NewRibEntry(1, uint32(time.Now().Unix()), 0, p) + e2 := NewRibEntry(2, uint32(time.Now().Unix()), 0, p) + e3 := NewRibEntry(3, uint32(time.Now().Unix()), 0, p) + + r1 := NewRib(1, bgp.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, + } + err = r2.DecodeFromBytes(b1) + if err != nil { + t.Fatal(err) + } + assert.Equal(t, reflect.DeepEqual(r1, r2), true) +} + +func TestMrtRibWithAddPath(t *testing.T) { + aspath1 := []bgp.AsPathParamInterface{ + bgp.NewAsPathParam(2, []uint16{1000}), + bgp.NewAsPathParam(1, []uint16{1001, 1002}), + bgp.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), + } + + e1 := NewRibEntry(1, uint32(time.Now().Unix()), 100, p) + e2 := NewRibEntry(2, uint32(time.Now().Unix()), 200, p) + e3 := NewRibEntry(3, uint32(time.Now().Unix()), 300, p) r1 := NewRib(1, bgp.NewIPAddrPrefix(24, "192.168.0.0"), []*RibEntry{e1, e2, e3}) b1, err := r1.Serialize() @@ -155,6 +218,7 @@ func TestMrtRib(t *testing.T) { } r2 := &Rib{ RouteFamily: bgp.RF_IPv4_UC, + isAddPath: true, } err = r2.DecodeFromBytes(b1) if err != nil { -- cgit v1.2.3