Skip to content

Commit cd9bbba

Browse files
committed
internal/table/destination: make it private as it's only used internally
1 parent 1459163 commit cd9bbba

File tree

6 files changed

+95
-95
lines changed

6 files changed

+95
-95
lines changed

internal/pkg/table/adj.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (adj *AdjRib) UpdateAdjRibOut(pathList []*Path) {
110110
}
111111
}
112112

113-
func (adj *AdjRib) walk(families []bgp.Family, fn func(*Destination) bool) {
113+
func (adj *AdjRib) walk(families []bgp.Family, fn func(*destination) bool) {
114114
for _, f := range families {
115115
if t, ok := adj.table[f]; ok {
116116
for _, d := range t.GetDestinations() {
@@ -124,7 +124,7 @@ func (adj *AdjRib) walk(families []bgp.Family, fn func(*Destination) bool) {
124124

125125
func (adj *AdjRib) PathList(rfList []bgp.Family, accepted bool) []*Path {
126126
pathList := make([]*Path, 0, adj.Count(rfList))
127-
adj.walk(rfList, func(d *Destination) bool {
127+
adj.walk(rfList, func(d *destination) bool {
128128
for _, p := range d.knownPathList {
129129
if accepted && p.IsRejected() {
130130
continue
@@ -138,7 +138,7 @@ func (adj *AdjRib) PathList(rfList []bgp.Family, accepted bool) []*Path {
138138

139139
func (adj *AdjRib) Count(rfList []bgp.Family) int {
140140
count := 0
141-
adj.walk(rfList, func(d *Destination) bool {
141+
adj.walk(rfList, func(d *destination) bool {
142142
count += len(d.knownPathList)
143143
return false
144144
})
@@ -157,7 +157,7 @@ func (adj *AdjRib) Accepted(rfList []bgp.Family) int {
157157

158158
func (adj *AdjRib) Drop(rfList []bgp.Family) []*Path {
159159
l := make([]*Path, 0, adj.Count(rfList))
160-
adj.walk(rfList, func(d *Destination) bool {
160+
adj.walk(rfList, func(d *destination) bool {
161161
for _, p := range d.knownPathList {
162162
w := p.Clone(true)
163163
w.SetDropped(true)
@@ -174,7 +174,7 @@ func (adj *AdjRib) Drop(rfList []bgp.Family) []*Path {
174174

175175
func (adj *AdjRib) DropStale(rfList []bgp.Family) []*Path {
176176
pathList := make([]*Path, 0, adj.Count(rfList))
177-
adj.walk(rfList, func(d *Destination) bool {
177+
adj.walk(rfList, func(d *destination) bool {
178178
for _, p := range d.knownPathList {
179179
if p.IsStale() {
180180
w := p.Clone(true)
@@ -190,7 +190,7 @@ func (adj *AdjRib) DropStale(rfList []bgp.Family) []*Path {
190190

191191
func (adj *AdjRib) StaleAll(rfList []bgp.Family) []*Path {
192192
pathList := make([]*Path, 0, adj.Count(rfList))
193-
adj.walk(rfList, func(d *Destination) bool {
193+
adj.walk(rfList, func(d *destination) bool {
194194
for i, p := range d.knownPathList {
195195
n := p.Clone(false)
196196
n.MarkStale(true)
@@ -207,7 +207,7 @@ func (adj *AdjRib) StaleAll(rfList []bgp.Family) []*Path {
207207

208208
func (adj *AdjRib) MarkLLGRStaleOrDrop(rfList []bgp.Family) []*Path {
209209
pathList := make([]*Path, 0, adj.Count(rfList))
210-
adj.walk(rfList, func(d *Destination) bool {
210+
adj.walk(rfList, func(d *destination) bool {
211211
for i, p := range d.knownPathList {
212212
if p.HasNoLLGR() {
213213
n := p.Clone(true)

internal/pkg/table/destination.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ func NewPeerInfo(g *oc.Global, p *oc.Neighbor, AS, localAS uint32, ID, localID n
136136
}
137137
}
138138

139-
type Destination struct {
139+
type destination struct {
140140
nlri bgp.NLRI
141141
knownPathList []*Path
142142
localIdMap *Bitmap
143143
}
144144

145-
func NewDestination(nlri bgp.NLRI, mapSize int, known ...*Path) *Destination {
146-
d := &Destination{
145+
func newDestination(nlri bgp.NLRI, mapSize int, known ...*Path) *destination {
146+
d := &destination{
147147
nlri: nlri,
148148
knownPathList: known,
149149
localIdMap: NewBitmap(mapSize),
@@ -155,11 +155,11 @@ func NewDestination(nlri bgp.NLRI, mapSize int, known ...*Path) *Destination {
155155
return d
156156
}
157157

158-
func (dd *Destination) GetNlri() bgp.NLRI {
158+
func (dd *destination) GetNlri() bgp.NLRI {
159159
return dd.nlri
160160
}
161161

162-
func (dd *Destination) GetAllKnownPathList() []*Path {
162+
func (dd *destination) GetAllKnownPathList() []*Path {
163163
return dd.knownPathList
164164
}
165165

@@ -171,7 +171,7 @@ func rsFilter(id string, as uint32, path *Path) bool {
171171
return id != GLOBAL_RIB_NAME && (path.GetSource().Address.String() == id || isASLoop(as, path))
172172
}
173173

174-
func (dd *Destination) GetKnownPathList(id string, as uint32) []*Path {
174+
func (dd *destination) GetKnownPathList(id string, as uint32) []*Path {
175175
list := make([]*Path, 0, len(dd.knownPathList))
176176
for _, p := range dd.knownPathList {
177177
if rsFilter(id, as, p) {
@@ -192,23 +192,23 @@ func getBestPath(id string, as uint32, pathList []*Path) *Path {
192192
return nil
193193
}
194194

195-
func (dd *Destination) GetBestPath(id string, as uint32) *Path {
195+
func (dd *destination) GetBestPath(id string, as uint32) *Path {
196196
p := getBestPath(id, as, dd.knownPathList)
197197
if p == nil || p.IsNexthopInvalid {
198198
return nil
199199
}
200200
return p
201201
}
202202

203-
func (dd *Destination) GetMultiBestPath(id string) []*Path {
203+
func (dd *destination) GetMultiBestPath(id string) []*Path {
204204
return getMultiBestPath(id, dd.knownPathList)
205205
}
206206

207207
// Calculates best-path among known paths for this destination.
208208
//
209209
// Modifies destination's state related to stored paths. Removes withdrawn
210210
// paths from known paths. Also, adds new paths to known paths.
211-
func (dest *Destination) Calculate(logger *slog.Logger, newPath *Path) *Update {
211+
func (dest *destination) Calculate(logger *slog.Logger, newPath *Path) *Update {
212212
oldKnownPathList := make([]*Path, len(dest.knownPathList))
213213
copy(oldKnownPathList, dest.knownPathList)
214214

@@ -250,7 +250,7 @@ func (dest *Destination) Calculate(logger *slog.Logger, newPath *Path) *Update {
250250
// since not all paths get installed into the table due to bgp policy and
251251
// we can receive withdraws for such paths and withdrawals may not be
252252
// stopped by the same policies.
253-
func (dest *Destination) explicitWithdraw(logger *slog.Logger, withdraw *Path) *Path {
253+
func (dest *destination) explicitWithdraw(logger *slog.Logger, withdraw *Path) *Path {
254254
logger.Debug("Removing withdrawals",
255255
slog.String("Topic", "Table"),
256256
slog.String("Key", dest.GetNlri().String()))
@@ -292,7 +292,7 @@ func (dest *Destination) explicitWithdraw(logger *slog.Logger, withdraw *Path) *
292292
//
293293
// Known paths will no longer have paths whose new version is present in
294294
// new paths.
295-
func (dest *Destination) implicitWithdraw(logger *slog.Logger, newPath *Path) {
295+
func (dest *destination) implicitWithdraw(logger *slog.Logger, newPath *Path) {
296296
found := -1
297297
for i, path := range dest.knownPathList {
298298
if path.NoImplicitWithdraw() {
@@ -318,7 +318,7 @@ func (dest *Destination) implicitWithdraw(logger *slog.Logger, newPath *Path) {
318318
}
319319
}
320320

321-
func (dest *Destination) insertSort(newPath *Path) {
321+
func (dest *destination) insertSort(newPath *Path) {
322322
// Find the correct position for newPath
323323
insertIdx := sort.Search(len(dest.knownPathList), func(i int) bool {
324324
//Determine where in the array newPath belongs. The slice
@@ -799,7 +799,7 @@ func compareByAge(path1, path2 *Path) *Path {
799799
return nil
800800
}
801801

802-
func (dest *Destination) String() string {
802+
func (dest *destination) String() string {
803803
return fmt.Sprintf("Destination NLRI: %s", dest.nlri.String())
804804
}
805805

@@ -812,11 +812,11 @@ type DestinationSelectOption struct {
812812
MultiPath bool
813813
}
814814

815-
func (d *Destination) MarshalJSON() ([]byte, error) {
815+
func (d *destination) MarshalJSON() ([]byte, error) {
816816
return json.Marshal(d.GetAllKnownPathList())
817817
}
818818

819-
func (d *Destination) Select(option ...DestinationSelectOption) *Destination {
819+
func (d *destination) Select(option ...DestinationSelectOption) *destination {
820820
id := GLOBAL_RIB_NAME
821821
var vrf *Vrf
822822
adj := false
@@ -871,5 +871,5 @@ func (d *Destination) Select(option ...DestinationSelectOption) *Destination {
871871
}
872872
}
873873
}
874-
return NewDestination(d.nlri, 0, paths...)
874+
return newDestination(d.nlri, 0, paths...)
875875
}

internal/pkg/table/destination_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ import (
3131
func TestDestinationNewIPv4(t *testing.T) {
3232
peerD := DestCreatePeer()
3333
pathD := DestCreatePath(peerD)
34-
ipv4d := NewDestination(pathD[0].GetNlri(), 0)
34+
ipv4d := newDestination(pathD[0].GetNlri(), 0)
3535
assert.NotNil(t, ipv4d)
3636
}
3737

3838
func TestDestinationNewIPv6(t *testing.T) {
3939
peerD := DestCreatePeer()
4040
pathD := DestCreatePath(peerD)
41-
ipv6d := NewDestination(pathD[0].GetNlri(), 0)
41+
ipv6d := newDestination(pathD[0].GetNlri(), 0)
4242
assert.NotNil(t, ipv6d)
4343
}
4444

4545
func TestDestinationGetNlri(t *testing.T) {
46-
dd := &Destination{}
46+
dd := &destination{}
4747
nlri, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.110.123.1/24"))
4848
dd.nlri = nlri
4949
r_nlri := dd.GetNlri()
5050
assert.Equal(t, r_nlri, nlri)
5151

5252
nlri2, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.110.123.2/24"))
53-
dd2 := NewDestination(nlri2, 0)
53+
dd2 := newDestination(nlri2, 0)
5454
r_nlri2 := dd2.GetNlri()
5555
assert.Equal(t, r_nlri2, nlri2)
5656
}
@@ -69,7 +69,7 @@ func TestCalculate2(t *testing.T) {
6969
peer1 := &PeerInfo{AS: 1, Address: netip.MustParseAddr("1.1.1.1")}
7070
path1 := ProcessMessage(update1, peer1, time.Now(), false)[0]
7171

72-
d := NewDestination(nlri, 0)
72+
d := newDestination(nlri, 0)
7373
d.Calculate(logger, path1)
7474

7575
// suppose peer2 sends grammaatically correct but semantically flawed update message
@@ -198,7 +198,7 @@ func TestTimeTieBreaker(t *testing.T) {
198198
peer2 := &PeerInfo{AS: 2, LocalAS: 1, Address: netip.MustParseAddr("2.2.2.2"), ID: netip.MustParseAddr("2.2.2.2")} // weaker router-id
199199
path2 := ProcessMessage(updateMsg, peer2, time.Now().Add(-1*time.Hour), false)[0] // older than path1
200200

201-
d := NewDestination(nlri, 0)
201+
d := newDestination(nlri, 0)
202202
d.Calculate(logger, path1)
203203
d.Calculate(logger, path2)
204204

@@ -207,7 +207,7 @@ func TestTimeTieBreaker(t *testing.T) {
207207

208208
// this option disables tie breaking by age
209209
SelectionOptions.ExternalCompareRouterId = true
210-
d = NewDestination(nlri, 0)
210+
d = newDestination(nlri, 0)
211211
d.Calculate(logger, path1)
212212
d.Calculate(logger, path2)
213213

@@ -331,7 +331,7 @@ func TestMultipath(t *testing.T) {
331331
updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, []bgp.PathNLRI{{NLRI: nlri}})
332332
path2 := ProcessMessage(updateMsg, peer2, time.Now(), false)[0]
333333

334-
d := NewDestination(nlri, 0)
334+
d := newDestination(nlri, 0)
335335
d.Calculate(logger, path2)
336336

337337
best, old, multi := d.Calculate(logger, path1).GetChanges(GLOBAL_RIB_NAME, 0, false)
@@ -384,7 +384,7 @@ func TestMultipath(t *testing.T) {
384384

385385
func TestIdMap(t *testing.T) {
386386
nlri, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.10.0.101/24"))
387-
d := NewDestination(nlri, 64)
387+
d := newDestination(nlri, 64)
388388
for i := 0; ; i++ {
389389
if id, err := d.localIdMap.FindandSetZeroBit(); err == nil {
390390
assert.Equal(t, uint(i+1), id)
@@ -437,7 +437,7 @@ func TestDestination_Calculate_ExplicitWithdraw(t *testing.T) {
437437
p1 := NewPath(bgp.RF_IPv4_UC, peer1, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
438438
p2 := NewPath(bgp.RF_IPv4_UC, peer2, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
439439

440-
d := NewDestination(nlri, 1, p1, p2)
440+
d := newDestination(nlri, 1, p1, p2)
441441

442442
// Test explicit withdraw
443443
withdrawPath := NewPath(bgp.RF_IPv4_UC, peer1, bgp.PathNLRI{NLRI: nlri}, true, attrs, time.Now(), false)
@@ -457,7 +457,7 @@ func TestDestination_Calculate_ImplicitWithdraw(t *testing.T) {
457457

458458
// Create initial path
459459
p1 := NewPath(bgp.RF_IPv4_UC, peer1, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
460-
d := NewDestination(nlri, 0, p1)
460+
d := newDestination(nlri, 0, p1)
461461

462462
// Send new path from same peer (should trigger implicit withdraw)
463463
newAttrs := []bgp.PathAttributeInterface{
@@ -481,7 +481,7 @@ func TestDestination_GetBestPath_InvalidNexthop(t *testing.T) {
481481

482482
p1 := NewPath(bgp.RF_IPv4_UC, peer1, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
483483

484-
d := NewDestination(nlri, 0, p1)
484+
d := newDestination(nlri, 0, p1)
485485

486486
p1.IsNexthopInvalid = false
487487
bestPath := d.GetBestPath("", 0)
@@ -504,7 +504,7 @@ func TestDestination_Select_BestAndMultiPath(t *testing.T) {
504504
p1 := NewPath(bgp.RF_IPv4_UC, peer1, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
505505
p2 := NewPath(bgp.RF_IPv4_UC, peer2, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
506506

507-
d := NewDestination(nlri, 0, p1, p2)
507+
d := newDestination(nlri, 0, p1, p2)
508508

509509
// Test best path selection
510510
selected := d.Select(DestinationSelectOption{Best: true})
@@ -650,7 +650,7 @@ func BenchmarkMultiPath(b *testing.B) {
650650

651651
b.Run("Benchmark Calculate", func(b *testing.B) {
652652
for range b.N {
653-
d := NewDestination(nlri, 0)
653+
d := newDestination(nlri, 0)
654654
b.StartTimer()
655655
for j := range pathList {
656656
d.Calculate(logger, pathList[j])
@@ -660,7 +660,7 @@ func BenchmarkMultiPath(b *testing.B) {
660660
})
661661

662662
b.Run("Benchmark GetMultiBestPath", func(b *testing.B) {
663-
d := NewDestination(nlri, 0)
663+
d := newDestination(nlri, 0)
664664
for j := range pathList {
665665
d.Calculate(logger, pathList[j])
666666
}
@@ -682,7 +682,7 @@ func TestDestination_Calculate_AddAndWithdrawPath(t *testing.T) {
682682
p2 := NewPath(bgp.RF_IPv4_UC, nil, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
683683
nlri, _ = bgp.NewIPAddrPrefix(netip.MustParsePrefix("13.2.5.0/24"))
684684
p3 := NewPath(bgp.RF_IPv4_UC, nil, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
685-
d := NewDestination(nlri, 0, p1, p2, p3)
685+
d := newDestination(nlri, 0, p1, p2, p3)
686686

687687
nlri, _ = bgp.NewIPAddrPrefix(netip.MustParsePrefix("13.2.6.0/24"))
688688
p4 := NewPath(bgp.RF_IPv4_UC, nil, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
@@ -696,7 +696,7 @@ func TestDestination_Calculate_AddAndWithdrawPath(t *testing.T) {
696696
// p1 is no implecit withdrawn
697697
nlri, _ = bgp.NewIPAddrPrefix(netip.MustParsePrefix("13.2.3.0/24"))
698698
p1 = NewPath(bgp.RF_IPv4_UC, nil, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), true)
699-
d = NewDestination(nlri, 0, p1, p2, p3)
699+
d = newDestination(nlri, 0, p1, p2, p3)
700700
update = d.Calculate(logger, p4)
701701
assert.Len(t, update.KnownPathList, 3)
702702
assert.Len(t, update.KnownPathList, 3)
@@ -708,7 +708,7 @@ func TestDestination_Calculate_AddAndWithdrawPath(t *testing.T) {
708708

709709
nlri, _ = bgp.NewIPAddrPrefix(netip.MustParsePrefix("13.2.8.0/24"))
710710
p5 := NewPath(bgp.RF_IPv4_UC, nil, bgp.PathNLRI{NLRI: nlri}, false, attrs, time.Now(), false)
711-
d = NewDestination(nlri, 0, p1, p2, p3, p5)
711+
d = newDestination(nlri, 0, p1, p2, p3, p5)
712712
update = d.Calculate(logger, p4)
713713

714714
assert.Len(t, update.KnownPathList, 4)

0 commit comments

Comments
 (0)