@@ -22,6 +22,7 @@ import (
22
22
"testing"
23
23
"time"
24
24
25
+ "github.com/osrg/gobgp/v3/internal/pkg/config"
25
26
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
26
27
27
28
"github.com/stretchr/testify/assert"
@@ -83,7 +84,7 @@ func TestCalculate2(t *testing.T) {
83
84
path1 := ProcessMessage (update1 , peer1 , time .Now ())[0 ]
84
85
85
86
d := NewDestination (nlri , 0 )
86
- d .Calculate (logger , path1 )
87
+ d .Calculate (logger , path1 , & config. RouteSelectionOptionsConfig {} )
87
88
88
89
// suppose peer2 sends grammaatically correct but semantically flawed update message
89
90
// which has a withdrawal nlri not advertised before
@@ -92,7 +93,7 @@ func TestCalculate2(t *testing.T) {
92
93
path2 := ProcessMessage (update2 , peer2 , time .Now ())[0 ]
93
94
assert .Equal (t , path2 .IsWithdraw , true )
94
95
95
- d .Calculate (logger , path2 )
96
+ d .Calculate (logger , path2 , & config. RouteSelectionOptionsConfig {} )
96
97
97
98
// we have a path from peer1 here
98
99
assert .Equal (t , len (d .knownPathList ), 1 )
@@ -102,7 +103,7 @@ func TestCalculate2(t *testing.T) {
102
103
path3 := ProcessMessage (update3 , peer2 , time .Now ())[0 ]
103
104
assert .Equal (t , path3 .IsWithdraw , false )
104
105
105
- d .Calculate (logger , path3 )
106
+ d .Calculate (logger , path3 , & config. RouteSelectionOptionsConfig {} )
106
107
107
108
// this time, we have paths from peer1 and peer2
108
109
assert .Equal (t , len (d .knownPathList ), 2 )
@@ -112,7 +113,7 @@ func TestCalculate2(t *testing.T) {
112
113
update4 := bgp .NewBGPUpdateMessage (nil , pathAttributes , []* bgp.IPAddrPrefix {nlri })
113
114
path4 := ProcessMessage (update4 , peer3 , time .Now ())[0 ]
114
115
115
- d .Calculate (logger , path4 )
116
+ d .Calculate (logger , path4 , & config. RouteSelectionOptionsConfig {} )
116
117
117
118
// we must have paths from peer1, peer2 and peer3
118
119
assert .Equal (t , len (d .knownPathList ), 3 )
@@ -156,7 +157,7 @@ func TestMedTieBreaker(t *testing.T) {
156
157
}()
157
158
158
159
// same AS
159
- assert .Equal (t , compareByMED (p0 , p1 ), p0 )
160
+ assert .Equal (t , compareByMED (p0 , p1 , & config. RouteSelectionOptionsConfig {} ), p0 )
160
161
161
162
p2 := func () * Path {
162
163
aspath := bgp .NewPathAttributeAsPath ([]bgp.AsPathParamInterface {bgp .NewAs4PathParam (bgp .BGP_ASPATH_ATTR_TYPE_SEQ , []uint32 {65003 })})
@@ -165,7 +166,7 @@ func TestMedTieBreaker(t *testing.T) {
165
166
}()
166
167
167
168
// different AS
168
- assert .Equal (t , compareByMED (p0 , p2 ), (* Path )(nil ))
169
+ assert .Equal (t , compareByMED (p0 , p2 , & config. RouteSelectionOptionsConfig {} ), (* Path )(nil ))
169
170
170
171
p3 := func () * Path {
171
172
aspath := bgp .NewPathAttributeAsPath ([]bgp.AsPathParamInterface {bgp .NewAs4PathParam (bgp .BGP_ASPATH_ATTR_TYPE_CONFED_SEQ , []uint32 {65003 , 65004 }), bgp .NewAs4PathParam (bgp .BGP_ASPATH_ATTR_TYPE_SEQ , []uint32 {65001 , 65003 })})
@@ -180,7 +181,7 @@ func TestMedTieBreaker(t *testing.T) {
180
181
}()
181
182
182
183
// ignore confed
183
- assert .Equal (t , compareByMED (p3 , p4 ), p3 )
184
+ assert .Equal (t , compareByMED (p3 , p4 , & config. RouteSelectionOptionsConfig {} ), p3 )
184
185
185
186
p5 := func () * Path {
186
187
attrs := []bgp.PathAttributeInterface {bgp .NewPathAttributeMultiExitDisc (0 )}
@@ -193,7 +194,7 @@ func TestMedTieBreaker(t *testing.T) {
193
194
}()
194
195
195
196
// no aspath
196
- assert .Equal (t , compareByMED (p5 , p6 ), p5 )
197
+ assert .Equal (t , compareByMED (p5 , p6 , & config. RouteSelectionOptionsConfig {} ), p5 )
197
198
}
198
199
199
200
func TestTimeTieBreaker (t * testing.T ) {
@@ -212,17 +213,19 @@ func TestTimeTieBreaker(t *testing.T) {
212
213
path2 := ProcessMessage (updateMsg , peer2 , time .Now ().Add (- 1 * time .Hour ))[0 ] // older than path1
213
214
214
215
d := NewDestination (nlri , 0 )
215
- d .Calculate (logger , path1 )
216
- d .Calculate (logger , path2 )
216
+ d .Calculate (logger , path1 , & config. RouteSelectionOptionsConfig {} )
217
+ d .Calculate (logger , path2 , & config. RouteSelectionOptionsConfig {} )
217
218
218
219
assert .Equal (t , len (d .knownPathList ), 2 )
219
220
assert .Equal (t , true , d .GetBestPath ("" , 0 ).GetSource ().ID .Equal (net.IP {2 , 2 , 2 , 2 })) // path from peer2 win
220
221
221
222
// this option disables tie breaking by age
222
- SelectionOptions .ExternalCompareRouterId = true
223
+ selectionOptions := config.RouteSelectionOptionsConfig {
224
+ ExternalCompareRouterId : true ,
225
+ }
223
226
d = NewDestination (nlri , 0 )
224
- d .Calculate (logger , path1 )
225
- d .Calculate (logger , path2 )
227
+ d .Calculate (logger , path1 , & selectionOptions )
228
+ d .Calculate (logger , path2 , & selectionOptions )
226
229
227
230
assert .Equal (t , len (d .knownPathList ), 2 )
228
231
assert .Equal (t , true , d .GetBestPath ("" , 0 ).GetSource ().ID .Equal (net.IP {1 , 1 , 1 , 1 })) // path from peer1 win
@@ -315,7 +318,9 @@ func updateMsgD3() *bgp.BGPMessage {
315
318
}
316
319
317
320
func TestMultipath (t * testing.T ) {
318
- UseMultiplePaths .Enabled = true
321
+ useMultiplePaths := config.UseMultiplePathsConfig {
322
+ Enabled : true ,
323
+ }
319
324
origin := bgp .NewPathAttributeOrigin (0 )
320
325
aspathParam := []bgp.AsPathParamInterface {bgp .NewAs4PathParam (2 , []uint32 {65000 })}
321
326
aspath := bgp .NewPathAttributeAsPath (aspathParam )
@@ -347,17 +352,17 @@ func TestMultipath(t *testing.T) {
347
352
path2 := ProcessMessage (updateMsg , peer2 , time .Now ())[0 ]
348
353
349
354
d := NewDestination (nlri [0 ], 0 )
350
- d .Calculate (logger , path2 )
355
+ d .Calculate (logger , path2 , & config. RouteSelectionOptionsConfig {} )
351
356
352
- best , old , multi := d .Calculate (logger , path1 ).GetChanges (GLOBAL_RIB_NAME , 0 , false )
357
+ best , old , multi := d .Calculate (logger , path1 , & config. RouteSelectionOptionsConfig {} ).GetChanges (GLOBAL_RIB_NAME , 0 , false , & useMultiplePaths )
353
358
assert .NotNil (t , best )
354
359
assert .Equal (t , old , path2 )
355
360
assert .Equal (t , len (multi ), 2 )
356
361
assert .Equal (t , len (d .GetKnownPathList (GLOBAL_RIB_NAME , 0 )), 2 )
357
362
358
363
path3 := path2 .Clone (true )
359
- dd := d .Calculate (logger , path3 )
360
- best , old , multi = dd .GetChanges (GLOBAL_RIB_NAME , 0 , false )
364
+ dd := d .Calculate (logger , path3 , & config. RouteSelectionOptionsConfig {} )
365
+ best , old , multi = dd .GetChanges (GLOBAL_RIB_NAME , 0 , false , & useMultiplePaths )
361
366
assert .Nil (t , best )
362
367
assert .Equal (t , old , path1 )
363
368
assert .Equal (t , len (multi ), 1 )
@@ -374,8 +379,8 @@ func TestMultipath(t *testing.T) {
374
379
}
375
380
updateMsg = bgp .NewBGPUpdateMessage (nil , pathAttributes , nlri )
376
381
path4 := ProcessMessage (updateMsg , peer3 , time .Now ())[0 ]
377
- dd = d .Calculate (logger , path4 )
378
- best , _ , multi = dd .GetChanges (GLOBAL_RIB_NAME , 0 , false )
382
+ dd = d .Calculate (logger , path4 , & config. RouteSelectionOptionsConfig {} )
383
+ best , _ , multi = dd .GetChanges (GLOBAL_RIB_NAME , 0 , false , & useMultiplePaths )
379
384
assert .NotNil (t , best )
380
385
assert .Equal (t , len (multi ), 1 )
381
386
assert .Equal (t , len (d .GetKnownPathList (GLOBAL_RIB_NAME , 0 )), 2 )
@@ -389,12 +394,10 @@ func TestMultipath(t *testing.T) {
389
394
}
390
395
updateMsg = bgp .NewBGPUpdateMessage (nil , pathAttributes , nlri )
391
396
path5 := ProcessMessage (updateMsg , peer2 , time .Now ())[0 ]
392
- best , _ , multi = d .Calculate (logger , path5 ).GetChanges (GLOBAL_RIB_NAME , 0 , false )
397
+ best , _ , multi = d .Calculate (logger , path5 , & config. RouteSelectionOptionsConfig {} ).GetChanges (GLOBAL_RIB_NAME , 0 , false , & useMultiplePaths )
393
398
assert .NotNil (t , best )
394
399
assert .Equal (t , len (multi ), 2 )
395
400
assert .Equal (t , len (d .GetKnownPathList (GLOBAL_RIB_NAME , 0 )), 3 )
396
-
397
- UseMultiplePaths .Enabled = false
398
401
}
399
402
400
403
func TestIdMap (t * testing.T ) {
0 commit comments