summaryrefslogtreecommitdiffhomepage
path: root/packet/mrt/mrt_test.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-05-29 11:09:40 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-06-01 09:31:52 +0900
commit99336372ab2ae8a3b61af63abbcbd70223a1dfe1 (patch)
tree28d439e6d04884e78fb53279f8c3f43675743e49 /packet/mrt/mrt_test.go
parentb529f81ed7d8428200a3f5dcf99a57db9f9f769e (diff)
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 <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/mrt/mrt_test.go')
-rw-r--r--packet/mrt/mrt_test.go72
1 files changed, 68 insertions, 4 deletions
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 {