(t *testing.T)
| 372 | } |
| 373 | |
| 374 | func 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 | |
| 420 | func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) { |
| 421 | // create path ipv4 |
nothing calls this directly
no test coverage detected
searching dependent graphs…