diff options
-rw-r--r-- | table/destination_test.go | 10 | ||||
-rw-r--r-- | table/path.go | 11 | ||||
-rw-r--r-- | table/path_test.go | 21 | ||||
-rw-r--r-- | table/table.go | 4 | ||||
-rw-r--r-- | table/table_test.go | 24 |
5 files changed, 31 insertions, 39 deletions
diff --git a/table/destination_test.go b/table/destination_test.go index 7584ae47..29534c04 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -27,14 +27,14 @@ func TestDestinationNewIPv4(t *testing.T) { peerD := DestCreatePeer() msgD := DestCreateMSG(peerD) pathD := DestCreatePath(msgD) - ipv4d := NewIPv4Destination(pathD[0].getNlri()) + ipv4d := NewIPv4Destination(pathD[0].GetNlri()) assert.NotNil(t, ipv4d) } func TestDestinationNewIPv6(t *testing.T) { peerD := DestCreatePeer() msgD := DestCreateMSG(peerD) pathD := DestCreatePath(msgD) - ipv6d := NewIPv6Destination(pathD[0].getNlri()) + ipv6d := NewIPv6Destination(pathD[0].GetNlri()) assert.NotNil(t, ipv6d) } @@ -82,7 +82,7 @@ func TestDestinationSetBestPath(t *testing.T) { peerD := DestCreatePeer() msgD := DestCreateMSG(peerD) pathD := DestCreatePath(msgD) - ipv4d := NewIPv4Destination(pathD[0].getNlri()) + ipv4d := NewIPv4Destination(pathD[0].GetNlri()) ipv4d.setBestPath(pathD[0]) r_pathD := ipv4d.getBestPath() assert.Equal(t, r_pathD, pathD[0]) @@ -91,7 +91,7 @@ func TestDestinationGetBestPath(t *testing.T) { peerD := DestCreatePeer() msgD := DestCreateMSG(peerD) pathD := DestCreatePath(msgD) - ipv4d := NewIPv4Destination(pathD[0].getNlri()) + ipv4d := NewIPv4Destination(pathD[0].GetNlri()) ipv4d.setBestPath(pathD[0]) r_pathD := ipv4d.getBestPath() assert.Equal(t, r_pathD, pathD[0]) @@ -100,7 +100,7 @@ func TestDestinationCalculate(t *testing.T) { peerD := DestCreatePeer() msgD := DestCreateMSG(peerD) pathD := DestCreatePath(msgD) - ipv4d := NewIPv4Destination(pathD[0].getNlri()) + ipv4d := NewIPv4Destination(pathD[0].GetNlri()) //best path selection ipv4d.addNewPath(pathD[0]) ipv4d.addNewPath(pathD[1]) diff --git a/table/path.go b/table/path.go index 649ab10a..444fe838 100644 --- a/table/path.go +++ b/table/path.go @@ -37,8 +37,7 @@ type Path interface { getSourceVerNum() int setWithdraw(withdraw bool) isWithdraw() bool - setNlri(nlri bgp.AddrPrefixInterface) - getNlri() bgp.AddrPrefixInterface + GetNlri() bgp.AddrPrefixInterface getPrefix() net.IP setMedSetByTargetNeighbor(medSetByTargetNeighbor bool) getMedSetByTargetNeighbor() bool @@ -125,11 +124,7 @@ func (pd *PathDefault) isWithdraw() bool { return pd.withdraw } -func (pd *PathDefault) setNlri(nlri bgp.AddrPrefixInterface) { - pd.nlri = nlri -} - -func (pd *PathDefault) getNlri() bgp.AddrPrefixInterface { +func (pd *PathDefault) GetNlri() bgp.AddrPrefixInterface { return pd.nlri } @@ -170,7 +165,7 @@ func (pi *PathDefault) clone(forWithdrawal bool) Path { if !forWithdrawal { pathAttrs = pi.getPathAttributeMap() } - def := NewPathDefault(pi.getSource(), pi.getNlri(), pi.getSourceVerNum(), + def := NewPathDefault(pi.getSource(), pi.GetNlri(), pi.getSourceVerNum(), pi.getNexthop(), forWithdrawal, pathAttrs, pi.getMedSetByTargetNeighbor()) switch pi.ROUTE_FAMILY { case RF_IPv4_UC: diff --git a/table/path_test.go b/table/path_test.go index 3de2561e..e5a2397f 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -13,7 +13,7 @@ func TestPathNewIPv4(t *testing.T) { peerP := PathCreatePeer() msgP := PathCreateMSG(peerP) pathP := PathCreatePath(msgP) - ipv4p := NewIPv4Path(pathP[0].getSource(), pathP[0].getNlri(), pathP[0].getSourceVerNum(), pathP[0].getNexthop(), + ipv4p := NewIPv4Path(pathP[0].getSource(), pathP[0].GetNlri(), pathP[0].getSourceVerNum(), pathP[0].getNexthop(), true, pathP[0].getPathAttributeMap(), pathP[0].getMedSetByTargetNeighbor()) assert.NotNil(t, ipv4p) } @@ -21,7 +21,7 @@ func TestPathNewIPv6(t *testing.T) { peerP := PathCreatePeer() msgP := PathCreateMSG(peerP) pathP := PathCreatePath(msgP) - ipv6p := NewIPv6Path(pathP[0].getSource(), pathP[0].getNlri(), pathP[0].getSourceVerNum(), pathP[0].getNexthop(), + ipv6p := NewIPv6Path(pathP[0].getSource(), pathP[0].GetNlri(), pathP[0].getSourceVerNum(), pathP[0].getNexthop(), true, pathP[0].getPathAttributeMap(), pathP[0].getMedSetByTargetNeighbor()) assert.NotNil(t, ipv6p) } @@ -122,20 +122,16 @@ func TestPathGetWithdaw(t *testing.T) { r_wd := pd.isWithdraw() assert.Equal(t, r_wd, wd) } -func TestPathSetNlri(t *testing.T) { - pd := &PathDefault{} - nlri := bgp.NewNLRInfo(24, "13.2.3.1") - pd.setNlri(nlri) - r_nlri := pd.getNlri() - assert.Equal(t, r_nlri, nlri) -} + func TestPathGetNlri(t *testing.T) { - pd := &PathDefault{} nlri := bgp.NewNLRInfo(24, "13.2.3.2") - pd.setNlri(nlri) - r_nlri := pd.getNlri() + pd := &PathDefault{ + nlri: nlri, + } + r_nlri := pd.GetNlri() assert.Equal(t, r_nlri, nlri) } + func TestPathSetMedSetByTargetNeighbor(t *testing.T) { pd := &PathDefault{} msbt := true @@ -143,6 +139,7 @@ func TestPathSetMedSetByTargetNeighbor(t *testing.T) { r_msbt := pd.getMedSetByTargetNeighbor() assert.Equal(t, r_msbt, msbt) } + func TestPathGetMedSetByTargetNeighbor(t *testing.T) { pd := &PathDefault{} msbt := true diff --git a/table/table.go b/table/table.go index 9b1aaa08..85110f7b 100644 --- a/table/table.go +++ b/table/table.go @@ -62,8 +62,8 @@ func insert(table Table, path Path) Destination { var dest Destination table.validatePath(path) - table.validateNlri(path.getNlri()) - dest = getOrCreateDest(table, path.getNlri()) + table.validateNlri(path.GetNlri()) + dest = getOrCreateDest(table, path.GetNlri()) if path.isWithdraw() { // withdraw insert diff --git a/table/table_test.go b/table/table_test.go index 63ae026f..47213a82 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -41,13 +41,13 @@ func TestTableDeleteDestByNlri(t *testing.T) { pathT := TableCreatePath(msgT) ipv4t := NewIPv4Table(0) for _, path := range pathT { - tableKey := ipv4t.tableKey(path.getNlri()) - dest := ipv4t.createDest(path.getNlri()) + tableKey := ipv4t.tableKey(path.GetNlri()) + dest := ipv4t.createDest(path.GetNlri()) ipv4t.setDestination(tableKey.String(), dest) } - tableKey := ipv4t.tableKey(pathT[0].getNlri()) + tableKey := ipv4t.tableKey(pathT[0].GetNlri()) gdest := ipv4t.getDestination(tableKey.String()) - rdest := deleteDestByNlri(ipv4t, pathT[0].getNlri()) + rdest := deleteDestByNlri(ipv4t, pathT[0].GetNlri()) assert.Equal(t, rdest, gdest) } @@ -57,12 +57,12 @@ func TestTableDeleteDest(t *testing.T) { pathT := TableCreatePath(msgT) ipv4t := NewIPv4Table(0) for _, path := range pathT { - tableKey := ipv4t.tableKey(path.getNlri()) - dest := ipv4t.createDest(path.getNlri()) + tableKey := ipv4t.tableKey(path.GetNlri()) + dest := ipv4t.createDest(path.GetNlri()) ipv4t.setDestination(tableKey.String(), dest) } - tableKey := ipv4t.tableKey(pathT[0].getNlri()) - dest := ipv4t.createDest(pathT[0].getNlri()) + tableKey := ipv4t.tableKey(pathT[0].GetNlri()) + dest := ipv4t.createDest(pathT[0].GetNlri()) ipv4t.setDestination(tableKey.String(), dest) deleteDest(ipv4t, dest) gdest := ipv4t.getDestination(tableKey.String()) @@ -82,8 +82,8 @@ func TestTableSetDestinations(t *testing.T) { ipv4t := NewIPv4Table(0) destinations := make(map[string]Destination) for _, path := range pathT { - tableKey := ipv4t.tableKey(path.getNlri()) - dest := ipv4t.createDest(path.getNlri()) + tableKey := ipv4t.tableKey(path.GetNlri()) + dest := ipv4t.createDest(path.GetNlri()) destinations[tableKey.String()] = dest } ipv4t.setDestinations(destinations) @@ -97,8 +97,8 @@ func TestTableGetDestinations(t *testing.T) { ipv4t := NewIPv4Table(0) destinations := make(map[string]Destination) for _, path := range pathT { - tableKey := ipv4t.tableKey(path.getNlri()) - dest := ipv4t.createDest(path.getNlri()) + tableKey := ipv4t.tableKey(path.GetNlri()) + dest := ipv4t.createDest(path.GetNlri()) destinations[tableKey.String()] = dest } ipv4t.setDestinations(destinations) |