(t *testing.T)
| 262 | } |
| 263 | |
| 264 | func 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 | |
| 295 | func TestPolicyMatchAndAccept(t *testing.T) { |
| 296 | // create path |
nothing calls this directly
no test coverage detected
searching dependent graphs…