MCPcopy
hub / github.com/osrg/gobgp / TestWatchPostUpdateWithLocalRoute

Function TestWatchPostUpdateWithLocalRoute

pkg/server/server_test.go:46–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44var logger = slog.Default()
45
46func TestWatchPostUpdateWithLocalRoute(t *testing.T) {
47 s := NewBgpServer()
48 go s.Serve()
49 err := s.StartBgp(context.Background(), &api.StartBgpRequest{
50 Global: &api.Global{
51 Asn: 1,
52 RouterId: "1.1.1.1",
53 ListenPort: -1,
54 },
55 })
56 require.NoError(t, err)
57 defer s.StopBgp(context.Background(), &api.StopBgpRequest{})
58
59 // Add local path (no PeerInfo)
60 panh, _ := bgp.NewPathAttributeNextHop(netip.MustParseAddr("10.0.0.1"))
61 attrs := []bgp.PathAttributeInterface{
62 bgp.NewPathAttributeOrigin(0),
63 panh,
64 }
65 nlri, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.10.0.0/24"))
66 path, _ := apiutil.NewPath(bgp.RF_IPv4_UC, nlri, false, attrs, time.Now())
67
68 _, err = s.AddPath(apiutil.AddPathRequest{Paths: []*apiutil.Path{mustApi2apiutilPath(path)}})
69 require.NoError(t, err)
70
71 // Calling watch with initPostUpdate=true and a peerAddress filter.
72 // This will traverse the global RIB, encounter the local path with no PeerInfo,
73 // and apply the postUpdateFilter. It should not panic.
74 s.watch(WatchPostUpdate(true, "10.2.2.2", ""))
75}
76
77func TestStop(t *testing.T) {
78 assert := assert.New(t)

Callers

nothing calls this directly

Calls 12

ServeMethod · 0.95
StartBgpMethod · 0.95
StopBgpMethod · 0.95
AddPathMethod · 0.95
watchMethod · 0.95
NewPathAttributeNextHopFunction · 0.92
NewPathAttributeOriginFunction · 0.92
NewIPAddrPrefixFunction · 0.92
NewPathFunction · 0.92
NewBgpServerFunction · 0.85
mustApi2apiutilPathFunction · 0.85
WatchPostUpdateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…