@@ -11,6 +11,7 @@ import (
1111 "github.com/osrg/gobgp/v4/pkg/packet/bgp"
1212 gobgp "github.com/osrg/gobgp/v4/pkg/server"
1313 "github.com/stretchr/testify/require"
14+ "github.com/vishvananda/netlink"
1415 "k8s.io/utils/set"
1516)
1617
@@ -33,7 +34,7 @@ func newTestBgpServer(t *testing.T, routerID string) *gobgp.BgpServer {
3334 return server
3435}
3536
36- func listTestPrefixes (t * testing.T , server * gobgp.BgpServer , afi api.Family_Afi ) map [string ][]net.IP {
37+ func listTestPrefixNextHops (t * testing.T , server * gobgp.BgpServer , afi api.Family_Afi ) map [string ][]net.IP {
3738 t .Helper ()
3839
3940 prefixes := map [string ][]net.IP {}
@@ -69,15 +70,15 @@ func TestReconcileRoutesAddsAndWithdrawsIPv4Routes(t *testing.T) {
6970 require .NoError (t , controller .reconcileRoutes (prefixMap {
7071 api .Family_AFI_IP : set .New (prefix ),
7172 }))
72- routes := listTestPrefixes (t , controller .config .BgpServer , api .Family_AFI_IP )
73+ routes := listTestPrefixNextHops (t , controller .config .BgpServer , api .Family_AFI_IP )
7374 require .Contains (t , routes , prefix )
7475 require .Len (t , routes [prefix ], 1 )
7576 require .True (t , net .ParseIP (routerID ).Equal (routes [prefix ][0 ]))
7677
7778 require .NoError (t , controller .reconcileRoutes (prefixMap {
7879 api .Family_AFI_IP : set .New [string ](),
7980 }))
80- require .NotContains (t , listTestPrefixes (t , controller .config .BgpServer , api .Family_AFI_IP ), prefix )
81+ require .NotContains (t , listTestPrefixNextHops (t , controller .config .BgpServer , api .Family_AFI_IP ), prefix )
8182}
8283
8384func TestGetPathRequest (t * testing.T ) {
@@ -204,12 +205,21 @@ func TestGetNextHopFromPathAttributes(t *testing.T) {
204205 }
205206}
206207
207- func TestGetNextHopAttributeUsesCachedLocalAddress (t * testing.T ) {
208+ func TestGetNextHopAttributeReusesInitializedNeighborLocalAddress (t * testing.T ) {
208209 const neighbor = "192.0.2.1"
209- localAddress := net .ParseIP ("192.0.2.10" )
210- controller := & Controller {config : & Configuration {
211- NeighborLocalAddresses : map [string ]net.IP {neighbor : localAddress },
212- }}
210+ neighborAddress := net .ParseIP (neighbor )
211+ startupAddress := net .ParseIP ("192.0.2.10" )
212+ routeSource := startupAddress
213+ config := & Configuration {
214+ NeighborAddresses : []net.IP {neighborAddress },
215+ AllowedSourceAddresses : []net.IP {startupAddress },
216+ }
217+ require .NoError (t , config .initNeighborLocalAddressesWithRouteLookup (func (address net.IP ) ([]netlink.Route , error ) {
218+ require .True (t , neighborAddress .Equal (address ))
219+ return []netlink.Route {{Src : routeSource }}, nil
220+ }))
213221
214- require .True (t , localAddress .Equal (controller .getNextHopAttribute (net .ParseIP (neighbor ))))
222+ routeSource = net .ParseIP ("192.0.2.20" )
223+ controller := & Controller {config : config }
224+ require .True (t , startupAddress .Equal (controller .getNextHopAttribute (neighborAddress )))
215225}
0 commit comments