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

Function TestPolicyMatchAndReject

internal/pkg/table/policy_test.go:264–293  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

262}
263
264func TestPolicyMatchAndReject(t *testing.T) {
265 // create path
266 peer := &PeerInfo{AS: 65001, Address: netip.MustParseAddr("10.0.0.1")}
267 origin := bgp.NewPathAttributeOrigin(0)
268 aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
269 aspath := bgp.NewPathAttributeAsPath(aspathParam)
270 nexthop, _ := bgp.NewPathAttributeNextHop(netip.MustParseAddr("10.0.0.1"))
271 med := bgp.NewPathAttributeMultiExitDisc(0)
272 pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
273 nlri, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.10.0.101/24"))
274 updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, []bgp.PathNLRI{{NLRI: nlri}})
275 path := ProcessMessage(updateMsg, peer, time.Now(), false)[0]
276 // create policy
277 ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
278 ns := createNeighborSet("ns1", "10.0.0.1")
279 ds := oc.DefinedSets{}
280 ds.PrefixSets = []oc.PrefixSet{ps}
281 ds.NeighborSets = []oc.NeighborSet{ns}
282
283 s := createStatement("statement1", "ps1", "ns1", false)
284 pd := createPolicyDefinition("pd1", s)
285 pl := createRoutingPolicy(ds, pd)
286
287 r := NewRoutingPolicy(logger)
288 err := r.reload(pl)
289 assert.NoError(t, err)
290 pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
291 assert.Equal(t, ROUTE_TYPE_REJECT, pType)
292 assert.Equal(t, newPath, path)
293}
294
295func TestPolicyMatchAndAccept(t *testing.T) {
296 // create path

Callers

nothing calls this directly

Calls 15

reloadMethod · 0.95
NewPathAttributeOriginFunction · 0.92
NewAsPathParamFunction · 0.92
NewPathAttributeAsPathFunction · 0.92
NewPathAttributeNextHopFunction · 0.92
NewIPAddrPrefixFunction · 0.92
NewBGPUpdateMessageFunction · 0.92
ProcessMessageFunction · 0.85
createPrefixSetFunction · 0.85
createNeighborSetFunction · 0.85
createStatementFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…