table: fix the previous commit

update unit tests.

Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
FUJITA Tomonori
2015-01-07 01:23:21 -08:00
parent 4bd5611c10
commit 1268cfca64
2 changed files with 6 additions and 81 deletions
+6 -47
View File
@@ -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])
}
}
}
-34
View File
@@ -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)