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

Function TestUpdatePathAttrsRTCOriginatorIDWithLocalID

internal/pkg/table/path_test.go:415–464  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

413}
414
415func TestUpdatePathAttrsRTCOriginatorIDWithLocalID(t *testing.T) {
416 global := &oc.Global{Config: oc.GlobalConfig{As: 65000, RouterId: netip.MustParseAddr("10.0.0.1")}}
417 clusterID := netip.MustParseAddr("10.0.0.100")
418 info := &PeerInfo{
419 AS: 65000,
420 LocalAS: 65000,
421 LocalAddress: netip.MustParseAddr("192.168.0.1"),
422 RouteReflectorClient: true,
423 RouteReflectorClusterID: clusterID,
424 PeerType: oc.PEER_TYPE_INTERNAL,
425 }
426
427 // Case 1: Source with Address (not local) set - should use LocalID as Originator ID
428 sourceWithLocalID := &PeerInfo{
429 AS: 65000,
430 LocalAS: 65000,
431 ID: netip.MustParseAddr("10.0.0.2"),
432 LocalID: netip.MustParseAddr("10.0.0.100"), // Different from global RouterId
433 Address: netip.MustParseAddr("10.0.0.2"), // Not local path (IsLocal() == false)
434 }
435 nlri := bgp.PathNLRI{NLRI: bgp.NewRouteTargetMembershipNLRI(0, nil)}
436 nlriAttr, _ := bgp.NewPathAttributeMpReachNLRI(bgp.RF_RTC_UC, []bgp.PathNLRI{nlri})
437 attrs := []bgp.PathAttributeInterface{
438 bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP),
439 nlriAttr,
440 }
441 pathWithLocalID := NewPath(bgp.RF_RTC_UC, sourceWithLocalID, nlri, false, attrs, time.Now(), false)
442 updatedPath1 := UpdatePathAttrs(logger, global, info, pathWithLocalID)
443
444 attr1 := updatedPath1.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGINATOR_ID)
445 originatorID1 := attr1.(*bgp.PathAttributeOriginatorId).Value
446 assert.True(t, originatorID1.IsValid(), "Originator ID attribute should be set for RTC route")
447 assert.Equal(t, "10.0.0.100", originatorID1.String(),
448 "Originator ID should be src.LocalID when path is not local")
449
450 // Case 2: Source with LocalID nil - should fall back to global.Config.RouterId
451 sourceWithoutLocalID := &PeerInfo{
452 AS: 65000,
453 LocalAS: 65000,
454 ID: netip.MustParseAddr("10.0.0.2"),
455 }
456 pathWithoutLocalID := NewPath(bgp.RF_RTC_UC, sourceWithoutLocalID, nlri, false, attrs, time.Now(), false)
457 updatedPath2 := UpdatePathAttrs(logger, global, info, pathWithoutLocalID)
458
459 attr2 := updatedPath2.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGINATOR_ID)
460 originatorID2 := attr2.(*bgp.PathAttributeOriginatorId).Value
461 assert.True(t, originatorID2.IsValid(), "Originator ID attribute should be set for RTC route")
462 assert.Equal(t, "10.0.0.1", originatorID2.String(),
463 "Originator ID should be global.Config.RouterId when path is local")
464}
465
466func TestNLRIToIPNet(t *testing.T) {
467 _, n1, _ := net.ParseCIDR("30.30.30.0/24")

Callers

nothing calls this directly

Calls 8

NewPathAttributeOriginFunction · 0.92
UpdatePathAttrsFunction · 0.85
getPathAttrMethod · 0.80
NewPathFunction · 0.70
StringMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…