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

Function TestPolicyRejectOnlyNeighborSet

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

Source from the content-addressed store, hash-verified

372}
373
374func TestPolicyRejectOnlyNeighborSet(t *testing.T) {
375 // create path
376 peer := &PeerInfo{AS: 65001, Address: netip.MustParseAddr("10.0.1.1")}
377 origin := bgp.NewPathAttributeOrigin(0)
378 aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
379 aspath := bgp.NewPathAttributeAsPath(aspathParam)
380 nexthop, _ := bgp.NewPathAttributeNextHop(netip.MustParseAddr("10.0.1.1"))
381 med := bgp.NewPathAttributeMultiExitDisc(0)
382 pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
383 nlri, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.10.1.101/24"))
384 updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, []bgp.PathNLRI{{NLRI: nlri}})
385 path1 := ProcessMessage(updateMsg, peer, time.Now(), false)[0]
386
387 peer = &PeerInfo{AS: 65002, Address: netip.MustParseAddr("10.0.2.2")}
388 origin = bgp.NewPathAttributeOrigin(0)
389 aspathParam = []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002})}
390 aspath = bgp.NewPathAttributeAsPath(aspathParam)
391 nexthop, _ = bgp.NewPathAttributeNextHop(netip.MustParseAddr("10.0.2.2"))
392 med = bgp.NewPathAttributeMultiExitDisc(0)
393 pathAttributes = []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
394 nlri, _ = bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.10.2.102/24"))
395 updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, []bgp.PathNLRI{{NLRI: nlri}})
396 path2 := ProcessMessage(updateMsg, peer, time.Now(), false)[0]
397
398 // create policy
399 ns := createNeighborSet("ns1", "10.0.1.1")
400 ds := oc.DefinedSets{}
401 ds.NeighborSets = []oc.NeighborSet{ns}
402
403 s := createStatement("statement1", "", "ns1", false)
404 pd := createPolicyDefinition("pd1", s)
405 pl := createRoutingPolicy(ds, pd)
406
407 // test
408 r := NewRoutingPolicy(logger)
409 err := r.reload(pl)
410 assert.NoError(t, err)
411 pType, newPath := r.policyMap["pd1"].Apply(logger, path1, nil)
412 assert.Equal(t, ROUTE_TYPE_REJECT, pType)
413 assert.Equal(t, newPath, path1)
414
415 pType2, newPath2 := r.policyMap["pd1"].Apply(logger, path2, nil)
416 assert.Equal(t, ROUTE_TYPE_NONE, pType2)
417 assert.Equal(t, newPath2, path2)
418}
419
420func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) {
421 // create path ipv4

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
createNeighborSetFunction · 0.85
createStatementFunction · 0.85
createPolicyDefinitionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…