@@ -24,6 +24,16 @@ import (
2424 "github.com/stretchr/testify/assert"
2525)
2626
27+ func TestCreateAdjTable (t * testing.T ) {
28+ table := NewAdjTable (logger , bgp .RF_RTC_UC )
29+ assert .NotNil (t , table .rtc )
30+ _ , checkType := table .rtc .(* routeFamilyRTCMap )
31+ assert .True (t , checkType )
32+
33+ table = NewAdjTable (logger , bgp .RF_FS_IPv4_VPN )
34+ assert .Nil (t , table .rtc )
35+ }
36+
2737func TestAddPath (t * testing.T ) {
2838 pi := & PeerInfo {}
2939 attrs := []bgp.PathAttributeInterface {bgp .NewPathAttributeOrigin (0 )}
@@ -162,3 +172,53 @@ func TestLLGRStale(t *testing.T) {
162172 assert .Equal (t , adj .Accepted ([]bgp.RouteFamily {family }), 1 )
163173 assert .Equal (t , 2 , len (adj .table [family ].destinations ))
164174}
175+
176+ func TestAdjRTC (t * testing.T ) {
177+ pi := & PeerInfo {}
178+ attrs := []bgp.PathAttributeInterface {bgp .NewPathAttributeOrigin (0 )}
179+
180+ rt1 , _ := bgp .ParseRouteTarget ("65520:1000000" )
181+ nlri1 := bgp .NewRouteTargetMembershipNLRI (65000 , rt1 )
182+ nlri1 .SetPathIdentifier (1 )
183+ hash1 , err := nlri1 .RouteTargetKey ()
184+ assert .Nil (t , err )
185+ p1 := NewPath (pi , nlri1 , false , attrs , time .Now (), false )
186+
187+ rt2 , _ := bgp .ParseRouteTarget ("65520:1000001" )
188+ nlri2 := bgp .NewRouteTargetMembershipNLRI (65000 , rt2 )
189+ nlri2 .SetPathIdentifier (2 )
190+ hash2 , err := nlri2 .RouteTargetKey ()
191+ assert .Nil (t , err )
192+ p2 := NewPath (pi , nlri2 , false , attrs , time .Now (), false )
193+
194+ nlri3 := bgp .NewRouteTargetMembershipNLRI (0 , nil )
195+ nlri3 .SetPathIdentifier (3 )
196+ p3 := NewPath (pi , nlri3 , false , attrs , time .Now (), false )
197+
198+ family := p1 .GetRouteFamily ()
199+ assert .Equal (t , family , bgp .RF_RTC_UC )
200+ families := []bgp.RouteFamily {family }
201+ adj := NewAdjRib (logger , families )
202+
203+ adj .Update ([]* Path {p1 , p2 , p3 })
204+ assert .Equal (t , adj .Count ([]bgp.RouteFamily {family }), 3 )
205+
206+ assert .True (t , adj .HasRTinRtcTable (bgp .DefaultRT ))
207+ assert .True (t , adj .HasRTinRtcTable (hash1 ))
208+ assert .True (t , adj .HasRTinRtcTable (hash2 ))
209+
210+ adj .Update ([]* Path {p1 .Clone (true )})
211+ assert .Equal (t , adj .Count ([]bgp.RouteFamily {family }), 2 )
212+ assert .True (t , adj .HasRTinRtcTable (bgp .DefaultRT ))
213+ assert .True (t , ! adj .HasRTinRtcTable (hash1 ))
214+ assert .True (t , adj .HasRTinRtcTable (hash2 ))
215+
216+ adj .Update ([]* Path {p3 .Clone (true )})
217+ assert .Equal (t , adj .Count ([]bgp.RouteFamily {family }), 1 )
218+ assert .True (t , ! adj .HasRTinRtcTable (bgp .DefaultRT ))
219+ assert .True (t , adj .HasRTinRtcTable (hash2 ))
220+
221+ adj .Update ([]* Path {p2 .Clone (true )})
222+ assert .Equal (t , adj .Count ([]bgp.RouteFamily {family }), 0 )
223+ assert .True (t , ! adj .HasRTinRtcTable (hash2 ))
224+ }
0 commit comments