From 1268cfca64c46c963fed587b2197ebcd3750b367 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Wed, 7 Jan 2015 01:23:21 -0800 Subject: table: fix the previous commit update unit tests. Signed-off-by: FUJITA Tomonori --- table/message_test.go | 53 +++++---------------------------------------- table/table_manager_test.go | 34 ----------------------------- 2 files changed, 6 insertions(+), 81 deletions(-) diff --git a/table/message_test.go b/table/message_test.go index ce29d899..d72fa833 100644 --- a/table/message_test.go +++ b/table/message_test.go @@ -40,28 +40,6 @@ func updateMsg1(as []uint16) *bgp.BGPMessage { return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttributes, nlri) } -func TestAs4PathNonAsTrans(t *testing.T) { - as := []uint16{65000, 4000, 40001} - m := updateMsg1(as).Body.(*bgp.BGPUpdate) - originalAsPath := m.PathAttributes[1] - UpdatePathAttrs4ByteAs(m) - assert.Equal(t, reflect.TypeOf(m.PathAttributes[0]).String(), "*bgp.PathAttributeOrigin") - assert.Equal(t, reflect.TypeOf(m.PathAttributes[1]).String(), "*bgp.PathAttributeAsPath") - assert.Equal(t, reflect.TypeOf(m.PathAttributes[2]).String(), "*bgp.PathAttributeNextHop") - assert.Equal(t, reflect.TypeOf(m.PathAttributes[3]).String(), "*bgp.PathAttributeMultiExitDisc") - - asAttr := m.PathAttributes[1].(*bgp.PathAttributeAsPath) - assert.Equal(t, len(asAttr.Value), 1) - for _, param := range asAttr.Value { - asParam := param.(*bgp.As4PathParam) - for i, v := range asParam.AS { - assert.Equal(t, v, as[i]) - } - } - UpdatePathAttrs2ByteAs(m) - assert.Equal(t, m.PathAttributes[1], originalAsPath) -} - func TestAsPathAsTrans(t *testing.T) { as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} m := updateMsg1(as).Body.(*bgp.BGPUpdate) @@ -72,8 +50,6 @@ func TestAsPathAsTrans(t *testing.T) { m.PathAttributes[3] = bgp.NewPathAttributeAs4Path(aspathParam) assert.Equal(t, len(m.PathAttributes), 5) - originalAsPath := m.PathAttributes[1] - originalAs4Path := m.PathAttributes[3] UpdatePathAttrs4ByteAs(m) assert.Equal(t, len(m.PathAttributes), 4) @@ -93,8 +69,12 @@ func TestAsPathAsTrans(t *testing.T) { } UpdatePathAttrs2ByteAs(m) assert.Equal(t, len(m.PathAttributes), 5) - assert.Equal(t, m.PathAttributes[1], originalAsPath) - assert.Equal(t, m.PathAttributes[4], originalAs4Path) + attr := m.PathAttributes[1].(*bgp.PathAttributeAsPath) + assert.Equal(t, len(attr.Value), 1) + assert.Equal(t, attr.Value[0].(*bgp.AsPathParam).AS, as) + attr2 := m.PathAttributes[4].(*bgp.PathAttributeAs4Path) + assert.Equal(t, len(attr2.Value), 1) + assert.Equal(t, attr2.Value[0].AS, as4) } func TestAs4PathUnchanged(t *testing.T) { @@ -119,24 +99,3 @@ func TestAs4PathUnchanged(t *testing.T) { } } } - -func TestAsPathUnchanged(t *testing.T) { - as := []uint16{65000, 4000, 5000, 4001} - m := updateMsg1(as).Body.(*bgp.BGPUpdate) - UpdatePathAttrs2ByteAs(m) - assert.Equal(t, len(m.PathAttributes), 4) - - assert.Equal(t, reflect.TypeOf(m.PathAttributes[0]).String(), "*bgp.PathAttributeOrigin") - assert.Equal(t, reflect.TypeOf(m.PathAttributes[1]).String(), "*bgp.PathAttributeAsPath") - assert.Equal(t, reflect.TypeOf(m.PathAttributes[2]).String(), "*bgp.PathAttributeNextHop") - assert.Equal(t, reflect.TypeOf(m.PathAttributes[3]).String(), "*bgp.PathAttributeMultiExitDisc") - - asAttr := m.PathAttributes[1].(*bgp.PathAttributeAsPath) - assert.Equal(t, len(asAttr.Value), 1) - for _, param := range asAttr.Value { - asParam := param.(*bgp.AsPathParam) - for i, v := range asParam.AS { - assert.Equal(t, v, as[i]) - } - } -} diff --git a/table/table_manager_test.go b/table/table_manager_test.go index 4440a909..f6cf2743 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -2184,40 +2184,6 @@ func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { } -func TestModifyPathAttribute(t *testing.T) { - tm := NewTableManager() - - bgpMessage := update_fromR1() - peer := peerR1() - pList, wList, err := tm.ProcessUpdate(peer, bgpMessage) - assert.Equal(t, len(pList), 1) - assert.Equal(t, len(wList), 0) - assert.NoError(t, err) - - path0 := pList[0] - path1 := path0.clone(false) - ipv4p := path1.(*IPv4Path) - ipv4p.PathDefault.pathAttrs = clonePathAttributes(path0.getPathAttrs()) - - _, attr1 := path1.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) - mx1 := attr1.(*bgp.PathAttributeMultiExitDisc) - original := mx1.Value - mx1.Value++ - - table := tm.Tables[bgp.RF_IPv4_UC] - dest := table.getDestination(table.tableKey(path0.getNlri()).String()).(*IPv4Destination) - path2 := dest.getKnownPathList() - _, attr2 := path2[0].getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) - mx2 := attr2.(*bgp.PathAttributeMultiExitDisc) - assert.Equal(t, original, mx2.Value) - - path3 := path0 - _, attr3 := path3.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) - mx3 := attr3.(*bgp.PathAttributeMultiExitDisc) - mx3.Value++ - assert.Equal(t, mx2.Value, mx3.Value) -} - func update_fromR1() *bgp.BGPMessage { origin := bgp.NewPathAttributeOrigin(0) -- cgit v1.2.3