diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-27 17:45:12 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-07-01 11:06:04 +0900 |
commit | 9b35be73826689b15839105ce0f386bbdaf56f06 (patch) | |
tree | a4a52ea351d6ab86a24846ffbfe4498a71aad39e /table/table_test.go | |
parent | c0b4a5943a5157f0de2e7b03827f714db704922e (diff) |
table: refactor Path/Destination/Table struct
Path/Destination/Table was defined as interface.
Simplify by making them normal struct.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/table_test.go')
-rw-r--r-- | table/table_test.go | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/table/table_test.go b/table/table_test.go index fe15204c..de8b271c 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -22,54 +22,40 @@ import ( "time" ) -func TestTableCreateDestDefault(t *testing.T) { - td := NewTableDefault(0) - nlri := bgp.NewNLRInfo(24, "13.2.3.1") - cd := td.createDest(nlri) - assert.Nil(t, cd) -} - -func TestTableTableKeyDefault(t *testing.T) { - td := NewTableDefault(0) - nlri := bgp.NewNLRInfo(24, "13.2.3.1") - tk := td.tableKey(nlri) - assert.Equal(t, tk, "") -} - func TestTableDeleteDestByNlri(t *testing.T) { peerT := TableCreatePeer() pathT := TableCreatePath(peerT) - ipv4t := NewIPv4Table(0) + ipv4t := NewTable(bgp.RF_IPv4_UC) for _, path := range pathT { tableKey := ipv4t.tableKey(path.GetNlri()) - dest := ipv4t.createDest(path.GetNlri()) + dest := NewDestination(path.GetNlri()) ipv4t.setDestination(tableKey, dest) } tableKey := ipv4t.tableKey(pathT[0].GetNlri()) gdest := ipv4t.getDestination(tableKey) - rdest := deleteDestByNlri(ipv4t, pathT[0].GetNlri()) + rdest := ipv4t.deleteDestByNlri(pathT[0].GetNlri()) assert.Equal(t, rdest, gdest) } func TestTableDeleteDest(t *testing.T) { peerT := TableCreatePeer() pathT := TableCreatePath(peerT) - ipv4t := NewIPv4Table(0) + ipv4t := NewTable(bgp.RF_IPv4_UC) for _, path := range pathT { tableKey := ipv4t.tableKey(path.GetNlri()) - dest := ipv4t.createDest(path.GetNlri()) + dest := NewDestination(path.GetNlri()) ipv4t.setDestination(tableKey, dest) } tableKey := ipv4t.tableKey(pathT[0].GetNlri()) - dest := ipv4t.createDest(pathT[0].GetNlri()) + dest := NewDestination(pathT[0].GetNlri()) ipv4t.setDestination(tableKey, dest) - deleteDest(ipv4t, dest) + ipv4t.deleteDest(dest) gdest := ipv4t.getDestination(tableKey) assert.Nil(t, gdest) } func TestTableGetRouteFamily(t *testing.T) { - ipv4t := NewIPv4Table(0) + ipv4t := NewTable(bgp.RF_IPv4_UC) rf := ipv4t.GetRoutefamily() assert.Equal(t, rf, bgp.RF_IPv4_UC) } @@ -77,11 +63,11 @@ func TestTableGetRouteFamily(t *testing.T) { func TestTableSetDestinations(t *testing.T) { peerT := TableCreatePeer() pathT := TableCreatePath(peerT) - ipv4t := NewIPv4Table(0) - destinations := make(map[string]Destination) + ipv4t := NewTable(bgp.RF_IPv4_UC) + destinations := make(map[string]*Destination) for _, path := range pathT { tableKey := ipv4t.tableKey(path.GetNlri()) - dest := ipv4t.createDest(path.GetNlri()) + dest := NewDestination(path.GetNlri()) destinations[tableKey] = dest } ipv4t.setDestinations(destinations) @@ -91,11 +77,11 @@ func TestTableSetDestinations(t *testing.T) { func TestTableGetDestinations(t *testing.T) { peerT := DestCreatePeer() pathT := DestCreatePath(peerT) - ipv4t := NewIPv4Table(0) - destinations := make(map[string]Destination) + ipv4t := NewTable(bgp.RF_IPv4_UC) + destinations := make(map[string]*Destination) for _, path := range pathT { tableKey := ipv4t.tableKey(path.GetNlri()) - dest := ipv4t.createDest(path.GetNlri()) + dest := NewDestination(path.GetNlri()) destinations[tableKey] = dest } ipv4t.setDestinations(destinations) @@ -111,17 +97,17 @@ func TableCreatePeer() []*PeerInfo { return peerT } -func TableCreatePath(peerT []*PeerInfo) []Path { +func TableCreatePath(peerT []*PeerInfo) []*Path { bgpMsgT1 := updateMsgT1() bgpMsgT2 := updateMsgT2() bgpMsgT3 := updateMsgT3() - pathT := make([]Path, 3) + pathT := make([]*Path, 3) for i, msg := range []*bgp.BGPMessage{bgpMsgT1, bgpMsgT2, bgpMsgT3} { updateMsgT := msg.Body.(*bgp.BGPUpdate) nlriList := updateMsgT.NLRI pathAttributes := updateMsgT.PathAttributes nlri_info := nlriList[0] - pathT[i], _ = CreatePath(peerT[i], &nlri_info, pathAttributes, false, time.Now()) + pathT[i] = NewPath(peerT[i], &nlri_info, false, pathAttributes, false, time.Now()) } return pathT } |