next gobgp/pkg/server/grpc_server.go:1060 │ gobgp/internal/pkg/table/policy.go:3932
│
cs := &api.Conditions{} │ cs := &api.Conditions{}
│ o, _ := NewMatchOption(s.Conditions.MatchPrefixSet.MatchSetOptions)
if s.Conditions.MatchPrefixSet.PrefixSet != "" { │ if s.Conditions.MatchPrefixSet.PrefixSet != "" {
cs.PrefixSet = &api.MatchSet{ │ cs.PrefixSet = &api.MatchSet{
Type: matchSetOptionsRestrictedTypeToAPI(s.Conditions.MatchPrefi │ Type: api.MatchSet_Type(o),
Name: s.Conditions.MatchPrefixSet.PrefixSet, │ Name: s.Conditions.MatchPrefixSet.PrefixSet,
} │ }
} │ }
if s.Conditions.MatchNeighborSet.NeighborSet != "" { │ if s.Conditions.MatchNeighborSet.NeighborSet != "" {
│ o, _ := NewMatchOption(s.Conditions.MatchNeighborSet.MatchSetOptions)
cs.NeighborSet = &api.MatchSet{ │ cs.NeighborSet = &api.MatchSet{
Type: matchSetOptionsRestrictedTypeToAPI(s.Conditions.MatchNeigh │ Type: api.MatchSet_Type(o),
Name: s.Conditions.MatchNeighborSet.NeighborSet, │ Name: s.Conditions.MatchNeighborSet.NeighborSet,
} │ }
} │ }
if s.Conditions.BgpConditions.AsPathLength.Operator != "" { │ if s.Conditions.BgpConditions.AsPathLength.Operator != "" {
cs.AsPathLength = &api.AsPathLength{ │ cs.AsPathLength = &api.AsPathLength{
Length: s.Conditions.BgpConditions.AsPathLength.Value, │ Length: s.Conditions.BgpConditions.AsPathLength.Value,
Type: api.AsPathLength_Type(s.Conditions.BgpConditions.AsPathL │ Type: api.AsPathLength_Type(s.Conditions.BgpConditions.AsPathL
} │ }
} │ }
if s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet != "" { │ if s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet != "" {
cs.AsPathSet = &api.MatchSet{ │ cs.AsPathSet = &api.MatchSet{
Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchAsPathSe │ Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchAsPathSe
Name: s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet, │ Name: s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet,
} │ }
} │ }
if s.Conditions.BgpConditions.MatchCommunitySet.CommunitySet != "" { │ if s.Conditions.BgpConditions.MatchCommunitySet.CommunitySet != "" {
cs.CommunitySet = &api.MatchSet{ │ cs.CommunitySet = &api.MatchSet{
Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchCommunit │ Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchCommunit
Name: s.Conditions.BgpConditions.MatchCommunitySet.CommunitySet, │ Name: s.Conditions.BgpConditions.MatchCommunitySet.CommunitySet,
} │ }
} │ }
if s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet != "" { │ if s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet != "" {
cs.ExtCommunitySet = &api.MatchSet{ │ cs.ExtCommunitySet = &api.MatchSet{
Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchExtCommu │ Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchExtCommu
Name: s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommuni │ Name: s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommuni
} │ }
} │ }
if s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet != "" { │ if s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet != "" {
cs.LargeCommunitySet = &api.MatchSet{ │ cs.LargeCommunitySet = &api.MatchSet{
Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchLargeCom │ Type: api.MatchSet_Type(s.Conditions.BgpConditions.MatchLargeCom
Name: s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCom │ Name: s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCom
} │ }
} │ }
if s.Conditions.BgpConditions.RouteType != "" { │ if s.Conditions.BgpConditions.RouteType != "" {
cs.RouteType = api.Conditions_RouteType(s.Conditions.BgpConditions.Route │ cs.RouteType = api.Conditions_RouteType(s.Conditions.BgpConditions.Route
} │ }
if len(s.Conditions.BgpConditions.NextHopInList) > 0 { │ if len(s.Conditions.BgpConditions.NextHopInList) > 0 {
cs.NextHopInList = s.Conditions.BgpConditions.NextHopInList │ cs.NextHopInList = s.Conditions.BgpConditions.NextHopInList
} │ }
if s.Conditions.BgpConditions.AfiSafiInList != nil { │ if s.Conditions.BgpConditions.AfiSafiInList != nil {
afiSafiIn := make([]*api.Family, 0) │ afiSafiIn := make([]*api.Family, 0)
for _, afiSafiType := range s.Conditions.BgpConditions.AfiSafiInList { │ for _, afiSafiType := range s.Conditions.BgpConditions.AfiSafiInList {
if mapped, ok := bgp.AddressFamilyValueMap[string(afiSafiType)]; │ if mapped, ok := bgp.AddressFamilyValueMap[string(afiSafiType)];
afi, safi := bgp.RouteFamilyToAfiSafi(mapped) │ afi, safi := bgp.RouteFamilyToAfiSafi(mapped)
afiSafiIn = append(afiSafiIn, &api.Family{Afi: api.Famil │ afiSafiIn = append(afiSafiIn, &api.Family{Afi: api.Famil
} │ }
} │ }
cs.AfiSafiIn = afiSafiIn │ cs.AfiSafiIn = afiSafiIn
} │ }
cs.RpkiResult = int32(s.Conditions.BgpConditions.RpkiValidationResult.ToInt()) │ cs.RpkiResult = int32(s.Conditions.BgpConditions.RpkiValidationResult.ToInt())
as := &api.Actions{ │ as := &api.Actions{
RouteAction: func() api.RouteAction { │ RouteAction: func() api.RouteAction {
switch s.Actions.RouteDisposition { │ switch s.Actions.RouteDisposition {
case config.ROUTE_DISPOSITION_ACCEPT_ROUTE: │ case config.ROUTE_DISPOSITION_ACCEPT_ROUTE:
return api.RouteAction_ACCEPT │ return api.RouteAction_ACCEPT
case config.ROUTE_DISPOSITION_REJECT_ROUTE: │ case config.ROUTE_DISPOSITION_REJECT_ROUTE:
return api.RouteAction_REJECT │ return api.RouteAction_REJECT
} │ }
return api.RouteAction_NONE │ return api.RouteAction_NONE
}(), │ }(),
Community: func() *api.CommunityAction { │ Community: func() *api.CommunityAction {
if len(s.Actions.BgpActions.SetCommunity.SetCommunityMethod.Comm │ if len(s.Actions.BgpActions.SetCommunity.SetCommunityMethod.Comm
return nil │ return nil
} │ }
return &api.CommunityAction{ │ return &api.CommunityAction{
Type: api.CommunityAction_Type(config.BgpSetCommu │ Type: api.CommunityAction_Type(config.BgpSetCommu
Communities: s.Actions.BgpActions.SetCommunity.SetCommun │ Communities: s.Actions.BgpActions.SetCommunity.SetCommun
}(), │ }(),
Med: func() *api.MedAction { │ Med: func() *api.MedAction {
medStr := strings.TrimSpace(string(s.Actions.BgpActions.SetMed)) │ medStr := strings.TrimSpace(string(s.Actions.BgpActions.SetMed))
if len(medStr) == 0 { │ if len(medStr) == 0 {
return nil │ return nil
} │ }
matches := _regexpMedActionType.FindStringSubmatch(medStr) │ matches := _regexpMedActionType.FindStringSubmatch(medStr)
if len(matches) == 0 { │ if len(matches) == 0 {
return nil │ return nil
} │ }
action := api.MedAction_REPLACE │ action := api.MedAction_REPLACE
switch matches[1] { │ switch matches[1] {
case "+", "-": │ case "+", "-":
action = api.MedAction_MOD │ action = api.MedAction_MOD
} │ }
value, err := strconv.ParseInt(matches[1]+matches[2], 10, 64) │ value, err := strconv.ParseInt(matches[1]+matches[2], 10, 64)
if err != nil { │ if err != nil {
return nil │ return nil
} │ }
return &api.MedAction{ │ return &api.MedAction{
Value: value, │ Value: value,
Type: action, │ Type: action,
} │ }
}(), │ }(),
AsPrepend: func() *api.AsPrependAction { │ AsPrepend: func() *api.AsPrependAction {
if len(s.Actions.BgpActions.SetAsPathPrepend.As) == 0 { │ if len(s.Actions.BgpActions.SetAsPathPrepend.As) == 0 {
return nil │ return nil
} │ }
var asn uint64 │ var asn uint64
useleft := false │ useleft := false
if s.Actions.BgpActions.SetAsPathPrepend.As != "last-as" { │ if s.Actions.BgpActions.SetAsPathPrepend.As != "last-as" {
asn, _ = strconv.ParseUint(s.Actions.BgpActions.SetAsPat │ asn, _ = strconv.ParseUint(s.Actions.BgpActions.SetAsPat
} else { │ } else {
useleft = true │ useleft = true
} │ }
return &api.AsPrependAction{ │ return &api.AsPrependAction{
Asn: uint32(asn), │ Asn: uint32(asn),
Repeat: uint32(s.Actions.BgpActions.SetAsPathPrepen │ Repeat: uint32(s.Actions.BgpActions.SetAsPathPrepen
UseLeftMost: useleft, │ UseLeftMost: useleft,
} │ }
}(), │ }(),
ExtCommunity: func() *api.CommunityAction { │ ExtCommunity: func() *api.CommunityAction {
if len(s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMetho │ if len(s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMetho
return nil │ return nil
} │ }
return &api.CommunityAction{ │ return &api.CommunityAction{
Type: api.CommunityAction_Type(config.BgpSetCommu │ Type: api.CommunityAction_Type(config.BgpSetCommu
Communities: s.Actions.BgpActions.SetExtCommunity.SetExt │ Communities: s.Actions.BgpActions.SetExtCommunity.SetExt
} │ }
}(), │ }(),
LargeCommunity: func() *api.CommunityAction { │ LargeCommunity: func() *api.CommunityAction {
if len(s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityM │ if len(s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityM
return nil │ return nil
} │ }
return &api.CommunityAction{ │ return &api.CommunityAction{
Type: api.CommunityAction_Type(config.BgpSetCommu │ Type: api.CommunityAction_Type(config.BgpSetCommu
Communities: s.Actions.BgpActions.SetLargeCommunity.SetL │ Communities: s.Actions.BgpActions.SetLargeCommunity.SetL
} │ }
}(), │ }(),
Nexthop: func() *api.NexthopAction { │ Nexthop: func() *api.NexthopAction {
if len(string(s.Actions.BgpActions.SetNextHop)) == 0 { │ if len(string(s.Actions.BgpActions.SetNextHop)) == 0 {
return nil │ return nil
} │ }
│
if string(s.Actions.BgpActions.SetNextHop) == "self" { │ if string(s.Actions.BgpActions.SetNextHop) == "self" {
return &api.NexthopAction{ │ return &api.NexthopAction{
Self: true, │ Self: true,
} │ }
} │ }
if string(s.Actions.BgpActions.SetNextHop) == "unchanged" { │ if string(s.Actions.BgpActions.SetNextHop) == "unchanged" {
return &api.NexthopAction{ │ return &api.NexthopAction{
Unchanged: true, │ Unchanged: true,
} │ }
} │ }
return &api.NexthopAction{ │ return &api.NexthopAction{
Address: string(s.Actions.BgpActions.SetNextHop), │ Address: string(s.Actions.BgpActions.SetNextHop),
} │ }
}(), │ }(),
LocalPref: func() *api.LocalPrefAction { │ LocalPref: func() *api.LocalPrefAction {
if s.Actions.BgpActions.SetLocalPref == 0 { │ if s.Actions.BgpActions.SetLocalPref == 0 {
return nil │ return nil
} │ }
return &api.LocalPrefAction{Value: s.Actions.BgpActions.SetLocal │ return &api.LocalPrefAction{Value: s.Actions.BgpActions.SetLocal
}(), │ }(),
} │ }
return &api.Statement{ │ return &api.Statement{
Name: s.Name, │ Name: s.Name,
Conditions: cs, │ Conditions: cs,
Actions: as, │ Actions: as,
} │ }
} │
next prev up gobgp/internal/pkg/table/policy_test.go:759 │ gobgp/internal/pkg/table/policy_test.go:1091
│
│
// setup │ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam1 := []bgp.AsPathParamInterface{ │ aspathParam1 := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{65001, 65000, 65010, 65004, 65005}), │ bgp.NewAs4PathParam(2, []uint32{
} │ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65010.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ })}
│
aspath := bgp.NewPathAttributeAsPath(aspathParam1) │ aspath := bgp.NewPathAttributeAsPath(aspathParam1)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(logger, updateMsg1.Body.(*bgp.BGPUpdate)) │ UpdatePathAttrs4ByteAs(logger, updateMsg1.Body.(*bgp.BGPUpdate))
path1 := ProcessMessage(updateMsg1, peer, time.Now())[0] │ path1 := ProcessMessage(updateMsg1, peer, time.Now())[0]
│
aspathParam2 := []bgp.AsPathParamInterface{ │ aspathParam2 := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{65010}), │ bgp.NewAs4PathParam(2, []uint32{
│ createAs4Value("65010.1"),
│ }),
} │ }
aspath2 := bgp.NewPathAttributeAsPath(aspathParam2) │ aspath2 := bgp.NewPathAttributeAsPath(aspathParam2)
pathAttributes = []bgp.PathAttributeInterface{origin, aspath2, nexthop, med} │ pathAttributes = []bgp.PathAttributeInterface{origin, aspath2, nexthop, med}
updateMsg2 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg2 := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(logger, updateMsg2.Body.(*bgp.BGPUpdate)) │ UpdatePathAttrs4ByteAs(logger, updateMsg2.Body.(*bgp.BGPUpdate))
path2 := ProcessMessage(updateMsg2, peer, time.Now())[0] │ path2 := ProcessMessage(updateMsg2, peer, time.Now())[0]
│
// create match condition │ // create match condition
asPathSet1 := config.AsPathSet{ │ asPathSet1 := config.AsPathSet{
AsPathSetName: "asset1", │ AsPathSetName: "asset1",
AsPathList: []string{"^65001"}, │ AsPathList: []string{fmt.Sprintf("^%d", createAs4Value("65001.1"))},
} │ }
│
asPathSet2 := config.AsPathSet{ │ asPathSet2 := config.AsPathSet{
AsPathSetName: "asset2", │ AsPathSetName: "asset2",
AsPathList: []string{"65005$"}, │ AsPathList: []string{fmt.Sprintf("%d$", createAs4Value("65005.1"))},
} │ }
│
asPathSet3 := config.AsPathSet{ │ asPathSet3 := config.AsPathSet{
AsPathSetName: "asset3", │ AsPathSetName: "asset3",
AsPathList: []string{"65004", "65005$"}, │ AsPathList: []string{
│ fmt.Sprintf("%d", createAs4Value("65004.1")),
│ fmt.Sprintf("%d$", createAs4Value("65005.1")),
│ },
} │ }
│
asPathSet4 := config.AsPathSet{ │ asPathSet4 := config.AsPathSet{
AsPathSetName: "asset4", │ AsPathSetName: "asset4",
AsPathList: []string{"65000$"}, │ AsPathList: []string{
│ fmt.Sprintf("%d$", createAs4Value("65000.1")),
│ },
} │ }
│
asPathSet5 := config.AsPathSet{ │ asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5", │ AsPathSetName: "asset5",
AsPathList: []string{"65010"}, │ AsPathList: []string{
│ fmt.Sprintf("%d", createAs4Value("65010.1")),
│ },
} │ }
│
asPathSet6 := config.AsPathSet{ │ asPathSet6 := config.AsPathSet{
AsPathSetName: "asset6", │ AsPathSetName: "asset6",
AsPathList: []string{"^65010$"}, │ AsPathList: []string{
│ fmt.Sprintf("%d$", createAs4Value("65010.1")),
│ },
} │ }
│
m := make(map[string]DefinedSet) │ m := make(map[string]DefinedSet)
for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3, │ for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3,
asPathSet4, asPathSet5, asPathSet6} { │ asPathSet4, asPathSet5, asPathSet6} {
a, _ := NewAsPathSet(s) │ a, _ := NewAsPathSet(s)
m[s.AsPathSetName] = a │ m[s.AsPathSetName] = a
} │ }
│
createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCon │ createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCon
matchSet := config.MatchAsPathSet{} │ matchSet := config.MatchAsPathSet{}
matchSet.AsPathSet = name │ matchSet.AsPathSet = name
matchSet.MatchSetOptions = option │ matchSet.MatchSetOptions = option
p, _ := NewAsPathCondition(matchSet) │ p, _ := NewAsPathCondition(matchSet)
if v, ok := m[name]; ok { │ if v, ok := m[name]; ok {
p.set = v.(*AsPathSet) │ p.set = v.(*AsPathSet)
} │ }
return p │ return p
} │ }
│
p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY) │ p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY)
p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY) │ p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY)
p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY) │ p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY)
p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY) │ p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY)
p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY) │ p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY)
p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY) │ p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY)
│
p7 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ALL) │ p7 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ALL)
p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT) │ p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT)
│
// test │ // test
assert.Equal(t, true, p1.Evaluate(path1, nil)) │ assert.Equal(t, true, p1.Evaluate(path1, nil))
assert.Equal(t, true, p2.Evaluate(path1, nil)) │ assert.Equal(t, true, p2.Evaluate(path1, nil))
assert.Equal(t, true, p3.Evaluate(path1, nil)) │ assert.Equal(t, true, p3.Evaluate(path1, nil))
assert.Equal(t, false, p4.Evaluate(path1, nil)) │ assert.Equal(t, false, p4.Evaluate(path1, nil))
assert.Equal(t, true, p5.Evaluate(path1, nil)) │ assert.Equal(t, true, p5.Evaluate(path1, nil))
assert.Equal(t, false, p6.Evaluate(path1, nil)) │ assert.Equal(t, false, p6.Evaluate(path1, nil))
assert.Equal(t, true, p6.Evaluate(path2, nil)) │ assert.Equal(t, true, p6.Evaluate(path2, nil))
│
assert.Equal(t, true, p7.Evaluate(path1, nil)) │ assert.Equal(t, true, p7.Evaluate(path1, nil))
assert.Equal(t, true, p8.Evaluate(path2, nil)) │ assert.Equal(t, true, p8.Evaluate(path2, nil))
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:1847 │ gobgp/internal/pkg/config/bgp_configs.go:3229
│
// original -> bgp:peer-group-name │ // original -> bgp:neighbor-address
// original -> bgp:peer-group-config │ // original -> bgp:neighbor-config
// Configuration parameters relating to the BGP neighbor or │ // Configuration parameters relating to the BGP neighbor or
// group. │ // group.
Config PeerGroupConfig `mapstructure:"config" json:"config,omitempty"` │ Config NeighborConfig `mapstructure:"config" json:"config,omitempty"`
// original -> bgp:peer-group-state │ // original -> bgp:neighbor-state
// State information relating to the BGP neighbor or group. │ // State information relating to the BGP neighbor or group.
State PeerGroupState `mapstructure:"state" json:"state,omitempty"` │ State NeighborState `mapstructure:"state" json:"state,omitempty"`
// original -> bgp:timers │ // original -> bgp:timers
// Timers related to a BGP neighbor or group. │ // Timers related to a BGP neighbor or group.
Timers Timers `mapstructure:"timers" json:"timers,omitempty"` │ Timers Timers `mapstructure:"timers" json:"timers,omitempty"`
// original -> bgp:transport │ // original -> bgp:transport
// Transport session parameters for the BGP neighbor or group. │ // Transport session parameters for the BGP neighbor or group.
Transport Transport `mapstructure:"transport" json:"transport,omitempty"` │ Transport Transport `mapstructure:"transport" json:"transport,omitempty"`
// original -> bgp:error-handling │ // original -> bgp:error-handling
// Error handling parameters used for the BGP neighbor or │ // Error handling parameters used for the BGP neighbor or
// group. │ // group.
ErrorHandling ErrorHandling `mapstructure:"error-handling" json:"error-handling, │ ErrorHandling ErrorHandling `mapstructure:"error-handling" json:"error-handling,
// original -> bgp:logging-options │ // original -> bgp:logging-options
// Logging options for events related to the BGP neighbor or │ // Logging options for events related to the BGP neighbor or
// group. │ // group.
LoggingOptions LoggingOptions `mapstructure:"logging-options" json:"logging-opti │ LoggingOptions LoggingOptions `mapstructure:"logging-options" json:"logging-opti
// original -> bgp:ebgp-multihop │ // original -> bgp:ebgp-multihop
// eBGP multi-hop parameters for the BGP neighbor or group. │ // eBGP multi-hop parameters for the BGP neighbor or group.
EbgpMultihop EbgpMultihop `mapstructure:"ebgp-multihop" json:"ebgp-multihop,omit │ EbgpMultihop EbgpMultihop `mapstructure:"ebgp-multihop" json:"ebgp-multihop,omit
// original -> bgp:route-reflector │ // original -> bgp:route-reflector
// Route reflector parameters for the BGP neighbor or group. │ // Route reflector parameters for the BGP neighbor or group.
RouteReflector RouteReflector `mapstructure:"route-reflector" json:"route-reflec │ RouteReflector RouteReflector `mapstructure:"route-reflector" json:"route-reflec
// original -> bgp:as-path-options │ // original -> bgp:as-path-options
// AS_PATH manipulation parameters for the BGP neighbor or │ // AS_PATH manipulation parameters for the BGP neighbor or
// group. │ // group.
AsPathOptions AsPathOptions `mapstructure:"as-path-options" json:"as-path-option │ AsPathOptions AsPathOptions `mapstructure:"as-path-options" json:"as-path-option
// original -> bgp:add-paths │ // original -> bgp:add-paths
// Parameters relating to the advertisement and receipt of │ // Parameters relating to the advertisement and receipt of
// multiple paths for a single NLRI (add-paths). │ // multiple paths for a single NLRI (add-paths).
AddPaths AddPaths `mapstructure:"add-paths" json:"add-paths,omitempty"` │ AddPaths AddPaths `mapstructure:"add-paths" json:"add-paths,omitempty"`
// original -> bgp:afi-safis │ // original -> bgp:afi-safis
// Per-address-family configuration parameters associated with │ // Per-address-family configuration parameters associated with
// the neighbor or group. │ // the neighbor or group.
AfiSafis []AfiSafi `mapstructure:"afi-safis" json:"afi-safis,omitempty"` │ AfiSafis []AfiSafi `mapstructure:"afi-safis" json:"afi-safis,omitempty"`
// original -> bgp:graceful-restart │ // original -> bgp:graceful-restart
// Parameters relating the graceful restart mechanism for BGP. │ // Parameters relating the graceful restart mechanism for BGP.
GracefulRestart GracefulRestart `mapstructure:"graceful-restart" json:"graceful- │ GracefulRestart GracefulRestart `mapstructure:"graceful-restart" json:"graceful-
// original -> rpol:apply-policy │ // original -> rpol:apply-policy
// Anchor point for routing policies in the model. │ // Anchor point for routing policies in the model.
// Import and export policies are with respect to the local │ // Import and export policies are with respect to the local
// routing table, i.e., export (send) and import (receive), │ // routing table, i.e., export (send) and import (receive),
// depending on the context. │ // depending on the context.
ApplyPolicy ApplyPolicy `mapstructure:"apply-policy" json:"apply-policy,omitempt │ ApplyPolicy ApplyPolicy `mapstructure:"apply-policy" json:"apply-policy,omitempt
// original -> bgp-mp:use-multiple-paths │ // original -> bgp-mp:use-multiple-paths
// Parameters related to the use of multiple paths for the │ // Parameters related to the use of multiple-paths for the same
// same NLRI. │ // NLRI when they are received only from this neighbor.
UseMultiplePaths UseMultiplePaths `mapstructure:"use-multiple-paths" json:"use-m │ UseMultiplePaths UseMultiplePaths `mapstructure:"use-multiple-paths" json:"use-m
// original -> gobgp:route-server │ // original -> gobgp:route-server
// Configure the local router as a route server. │ // Configure the local router as a route server.
RouteServer RouteServer `mapstructure:"route-server" json:"route-server,omitempt │ RouteServer RouteServer `mapstructure:"route-server" json:"route-server,omitempt
// original -> gobgp:ttl-security │ // original -> gobgp:ttl-security
// Configure TTL Security feature. │ // Configure TTL Security feature.
TtlSecurity TtlSecurity `mapstructure:"ttl-security" json:"ttl-security,omitempt │ TtlSecurity TtlSecurity `mapstructure:"ttl-security" json:"ttl-security,omitempt
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2463 │ gobgp/pkg/packet/bgp/bgp_test.go:2358
│
assert := assert.New(t) │ assert := assert.New(t)
│
var tests = []struct { │ var tests = []struct {
in []byte │ in []byte
want string │ want string
serialize bool │ serialize bool
err bool │ err bool
}{ │ }{
{ │ {
[]byte{ │ []byte{
0x04, 0x0c, 0x00, 0x0c, // type 1036, length 12 │ 0x04, 0x0a, 0x00, 0x0c, // type 1034, length 12
0x00, 0x00, // flags and reserved │ 0x00, 0x00, // flags and reserved
0x00, 0x88, 0xb8, // range: 35000 │ 0x00, 0x88, 0xb8, // range: 35000
0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T │ 0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T
}, │ },
`{"type":1036,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{" │ `{"type":1034,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{"
true, │ true,
false, │ false,
}, │ },
{ │ {
[]byte{ │ []byte{
0x04, 0x0c, 0x00, 0x0d, // type 1036, length 13 │ 0x04, 0x0a, 0x00, 0x0d, // type 1034, length 13
0x00, 0x00, // flags and reserved │ 0x00, 0x00, // flags and reserved
0x00, 0x88, 0xb8, // range: 35000 │ 0x00, 0x88, 0xb8, // range: 35000
0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L │ 0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L
}, │ },
`{"type":1036,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{" │ `{"type":1034,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{"
true, │ true,
false, │ false,
}, │ },
{ │ {
[]byte{ │ []byte{
0x04, 0x0c, 0x00, 0x17, // type 1036, length 23 │ 0x04, 0x0a, 0x00, 0x17, // type 1034, length 23
0x00, 0x00, // flags and reserved │ 0x00, 0x00, // flags and reserved
0x00, 0x88, 0xb8, // range: 35000 │ 0x00, 0x88, 0xb8, // range: 35000
0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L │ 0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L
0x0f, 0x42, 0x40, // range: 1000000 │ 0x0f, 0x42, 0x40, // range: 1000000
0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T │ 0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T
}, │ },
`{"type":1036,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{" │ `{"type":1034,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{"
true, │ true,
false, │ false,
}, │ },
{ │ {
[]byte{ │ []byte{
0x04, 0x0c, 0x00, 0x17, // type 1036, length 23 │ 0x04, 0x0a, 0x00, 0x17, // type 1034, length 23
0x00, 0x00, // flags and reserved │ 0x00, 0x00, // flags and reserved
0x00, 0x88, 0xb8, // range: 35000 │ 0x00, 0x88, 0xb8, // range: 35000
0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L │ 0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L
0x0f, 0x42, 0x40, // range: 1000000 │ 0x0f, 0x42, 0x40, // range: 1000000
0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T │ 0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T
0xff, 0xff, 0xff, // some random bytes - should be ignor │ 0xff, 0xff, 0xff, // some random bytes - should be ignor
}, │ },
`{"type":1036,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{" │ `{"type":1034,"flags":0,"ranges":[{"Range":35000,"FirstLabel":{"
false, │ false,
false, │ false,
}, │ },
{ │ {
[]byte{ │ []byte{
0x04, 0x0c, 0x00, 0xcc, // type 1036, length 204 (corrup │ 0x04, 0x0a, 0x00, 0xcc, // type 1034, length 204 (corrup
0x00, 0x00, // flags and reserved │ 0x00, 0x00, // flags and reserved
0x00, 0x88, 0xb8, // range: 35000 │ 0x00, 0x88, 0xb8, // range: 35000
0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T │ 0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94, // SID/Label T
}, │ },
"", │ "",
false, │ false,
true, │ true,
}, │ },
{ │ {
[]byte{ │ []byte{
0x04, 0x0c, 0x00, 0x11, // type 1036, length 23 │ 0x04, 0x0a, 0x00, 0x11, // type 1034, length 23
0x00, 0x00, // flags and reserved │ 0x00, 0x00, // flags and reserved
0x00, 0x88, 0xb8, // range: 35000 │ 0x00, 0x88, 0xb8, // range: 35000
0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L │ 0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49, // SID/L
0x0f, 0x42, 0x40, // range: 1000000 │ 0x0f, 0x42, 0x40, // range: 1000000
0x04, // No SID/Label sub-TLV │ 0x04, // No SID/Label sub-TLV
}, │ },
"", │ "",
false, │ false,
true, │ true,
}, │ },
} │ }
│
for _, test := range tests { │ for _, test := range tests {
tlv := LsTLVSrLocalBlock{} │ tlv := LsTLVSrCapabilities{}
if test.err { │ if test.err {
assert.Error(tlv.DecodeFromBytes(test.in)) │ assert.Error(tlv.DecodeFromBytes(test.in))
continue │ continue
} else { │ } else {
assert.NoError(tlv.DecodeFromBytes(test.in)) │ assert.NoError(tlv.DecodeFromBytes(test.in))
} │ }
│
got, err := tlv.MarshalJSON() │ got, err := tlv.MarshalJSON()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(got, []byte(test.want)) │ assert.Equal(got, []byte(test.want))
│
if test.serialize { │ if test.serialize {
s, err := tlv.Serialize() │ s, err := tlv.Serialize()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(test.in, s) │ assert.Equal(test.in, s)
} │ }
} │ }
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1109 │ gobgp/internal/pkg/table/table_manager_test.go:1644
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
SelectionOptions.ExternalCompareRouterId = true │
│
// low origin message │ // path1
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65100, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // path 1 from same peer but short AS_PATH
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65000, 65100}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer3 := peerR3() │ pList, err = tm.ProcessUpdate(peer1, bgpMessage2)
pList, err = tm.ProcessUpdate(peer3, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ checkPattr := func(expected *bgp.BGPMessage, actual *Path) {
expectedOrigin := pathAttributes[0] │ pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedOrigin := pathAttributes[0]
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
assert.Equal(t, expectedOrigin, pathOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
│ assert.Equal(t, expectedOrigin, pathOrigin)
expectedAsPath := pathAttributes[1] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ expectedAsPath := pathAttributes[1]
pathAspath := attr.(*bgp.PathAttributeAsPath) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
assert.Equal(t, expectedAsPath, pathAspath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
│ assert.Equal(t, expectedAsPath, pathAspath)
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ expectedNexthopAttr := pathAttributes[2]
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
expectedMed := pathAttributes[3] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ expectedMed := pathAttributes[3]
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
assert.Equal(t, expectedMed, pathMed) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
│ assert.Equal(t, expectedMed, pathMed)
// check PathAttribute length │
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │
│
│ // check PathAttribute length
│ assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs()))
│ }
│ checkPattr(bgpMessage2, path)
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:342 │ gobgp/internal/pkg/table/table_manager_test.go:1644
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low localpref message │ // path1
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65100, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // path 1 from same peer but short AS_PATH
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("0.0.0.0") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
var peer2 *PeerInfo = &PeerInfo{ │ pList, err = tm.ProcessUpdate(peer1, bgpMessage2)
Address: net.ParseIP("0.0.0.0"), │
} │
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ checkPattr := func(expected *bgp.BGPMessage, actual *Path) {
expectedOrigin := pathAttributes[0] │ pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedOrigin := pathAttributes[0]
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
assert.Equal(t, expectedOrigin, pathOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
│ assert.Equal(t, expectedOrigin, pathOrigin)
expectedAsPath := pathAttributes[1] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ expectedAsPath := pathAttributes[1]
pathAspath := attr.(*bgp.PathAttributeAsPath) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
assert.Equal(t, expectedAsPath, pathAspath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
│ assert.Equal(t, expectedAsPath, pathAspath)
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ expectedNexthopAttr := pathAttributes[2]
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
expectedMed := pathAttributes[3] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ expectedMed := pathAttributes[3]
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
assert.Equal(t, expectedMed, pathMed) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
│ assert.Equal(t, expectedMed, pathMed)
// check PathAttribute length │
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │
│
│ // check PathAttribute length
│ assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs()))
│ }
│ checkPattr(bgpMessage2, path)
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "0.0.0.0" │ expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:342 │ gobgp/internal/pkg/table/table_manager_test.go:1109
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│ SelectionOptions.ExternalCompareRouterId = true
│
// low localpref message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("0.0.0.0") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
var peer2 *PeerInfo = &PeerInfo{ │ peer3 := peerR3()
Address: net.ParseIP("0.0.0.0"), │ pList, err = tm.ProcessUpdate(peer3, bgpMessage2)
} │
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "0.0.0.0" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:621 │ gobgp/internal/pkg/table/table_manager_test.go:1644
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // path1
origin1 := bgp.NewPathAttributeOrigin(1) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65100, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // path 1 from same peer but short AS_PATH
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ pList, err = tm.ProcessUpdate(peer1, bgpMessage2)
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ checkPattr := func(expected *bgp.BGPMessage, actual *Path) {
expectedOrigin := pathAttributes[0] │ pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedOrigin := pathAttributes[0]
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
assert.Equal(t, expectedOrigin, pathOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
│ assert.Equal(t, expectedOrigin, pathOrigin)
expectedAsPath := pathAttributes[1] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ expectedAsPath := pathAttributes[1]
pathAspath := attr.(*bgp.PathAttributeAsPath) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
assert.Equal(t, expectedAsPath, pathAspath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
│ assert.Equal(t, expectedAsPath, pathAspath)
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ expectedNexthopAttr := pathAttributes[2]
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
expectedMed := pathAttributes[3] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ expectedMed := pathAttributes[3]
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
assert.Equal(t, expectedMed, pathMed) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
│ assert.Equal(t, expectedMed, pathMed)
// check PathAttribute length │
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │
│
│ // check PathAttribute length
│ assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs()))
│ }
│ checkPattr(bgpMessage2, path)
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:783 │ gobgp/internal/pkg/table/table_manager_test.go:1644
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // path1
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65100, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(500) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // path 1 from same peer but short AS_PATH
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ pList, err = tm.ProcessUpdate(peer1, bgpMessage2)
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ checkPattr := func(expected *bgp.BGPMessage, actual *Path) {
expectedOrigin := pathAttributes[0] │ pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedOrigin := pathAttributes[0]
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
assert.Equal(t, expectedOrigin, pathOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
│ assert.Equal(t, expectedOrigin, pathOrigin)
expectedAsPath := pathAttributes[1] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ expectedAsPath := pathAttributes[1]
pathAspath := attr.(*bgp.PathAttributeAsPath) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
assert.Equal(t, expectedAsPath, pathAspath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
│ assert.Equal(t, expectedAsPath, pathAspath)
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ expectedNexthopAttr := pathAttributes[2]
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
expectedMed := pathAttributes[3] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ expectedMed := pathAttributes[3]
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
assert.Equal(t, expectedMed, pathMed) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
│ assert.Equal(t, expectedMed, pathMed)
// check PathAttribute length │
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │
│
│ // check PathAttribute length
│ assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs()))
│ }
│ checkPattr(bgpMessage2, path)
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:945 │ gobgp/internal/pkg/table/table_manager_test.go:1644
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // path1
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65100, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // path 1 from same peer but short AS_PATH
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ pList, err = tm.ProcessUpdate(peer1, bgpMessage2)
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ checkPattr := func(expected *bgp.BGPMessage, actual *Path) {
expectedOrigin := pathAttributes[0] │ pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedOrigin := pathAttributes[0]
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
assert.Equal(t, expectedOrigin, pathOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
│ assert.Equal(t, expectedOrigin, pathOrigin)
expectedAsPath := pathAttributes[1] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ expectedAsPath := pathAttributes[1]
pathAspath := attr.(*bgp.PathAttributeAsPath) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
assert.Equal(t, expectedAsPath, pathAspath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
│ assert.Equal(t, expectedAsPath, pathAspath)
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ expectedNexthopAttr := pathAttributes[2]
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
expectedMed := pathAttributes[3] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ expectedMed := pathAttributes[3]
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
assert.Equal(t, expectedMed, pathMed) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
│ assert.Equal(t, expectedMed, pathMed)
// check PathAttribute length │
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │
│
│ // check PathAttribute length
│ assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs()))
│ }
│ checkPattr(bgpMessage2, path)
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:621 │ gobgp/internal/pkg/table/table_manager_test.go:1109
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│ SelectionOptions.ExternalCompareRouterId = true
│
// low origin message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(1) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer3 := peerR3()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer3, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:783 │ gobgp/internal/pkg/table/table_manager_test.go:1109
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│ SelectionOptions.ExternalCompareRouterId = true
│
// low origin message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(500) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer3 := peerR3()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer3, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:945 │ gobgp/internal/pkg/table/table_manager_test.go:1109
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│ SelectionOptions.ExternalCompareRouterId = true
│
// low origin message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer3 := peerR3()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer3, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:621 │ gobgp/internal/pkg/table/table_manager_test.go:342
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // low localpref message
origin1 := bgp.NewPathAttributeOrigin(1) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(0)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high localpref message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("0.0.0.0")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "0.0.0.0"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:783 │ gobgp/internal/pkg/table/table_manager_test.go:342
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // low localpref message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(500) │ med1 := bgp.NewPathAttributeMultiExitDisc(0)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high localpref message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("0.0.0.0")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "0.0.0.0"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:945 │ gobgp/internal/pkg/table/table_manager_test.go:342
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // low localpref message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(0)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high localpref message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("0.0.0.0")
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "0.0.0.0"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:783 │ gobgp/internal/pkg/table/table_manager_test.go:621
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(500) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:945 │ gobgp/internal/pkg/table/table_manager_test.go:621
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:945 │ gobgp/internal/pkg/table/table_manager_test.go:783
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low origin message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(500)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high origin message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:180 │ gobgp/internal/pkg/table/table_manager_test.go:1644
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low localpref message │ // path1
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65100, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // path 1 from same peer but short AS_PATH
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ pList, err = tm.ProcessUpdate(peer1, bgpMessage2)
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ checkPattr := func(expected *bgp.BGPMessage, actual *Path) {
expectedOrigin := pathAttributes[0] │ pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedOrigin := pathAttributes[0]
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
assert.Equal(t, expectedOrigin, pathOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
│ assert.Equal(t, expectedOrigin, pathOrigin)
expectedAsPath := pathAttributes[1] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ expectedAsPath := pathAttributes[1]
pathAspath := attr.(*bgp.PathAttributeAsPath) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
assert.Equal(t, expectedAsPath, pathAspath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
│ assert.Equal(t, expectedAsPath, pathAspath)
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ expectedNexthopAttr := pathAttributes[2]
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
expectedMed := pathAttributes[3] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ expectedMed := pathAttributes[3]
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
assert.Equal(t, expectedMed, pathMed) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
│ assert.Equal(t, expectedMed, pathMed)
// check PathAttribute length │
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │
│
│ // check PathAttribute length
│ assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs()))
│ }
│ checkPattr(bgpMessage2, path)
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "192.168.50.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:180 │ gobgp/internal/pkg/table/table_manager_test.go:1109
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│ SelectionOptions.ExternalCompareRouterId = true
│
// low localpref message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65000, 65100})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer3 := peerR3()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer3, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:180 │ gobgp/internal/pkg/table/table_manager_test.go:342
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low localpref message │ // low localpref message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(0)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // high localpref message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop2 := bgp.NewPathAttributeNextHop("0.0.0.0")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "0.0.0.0"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:180 │ gobgp/internal/pkg/table/table_manager_test.go:621
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low localpref message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:180 │ gobgp/internal/pkg/table/table_manager_test.go:783
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low localpref message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(500)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:180 │ gobgp/internal/pkg/table/table_manager_test.go:945
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// low localpref message │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(0) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// high localpref message │ // high origin message
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
origin2, aspath2, nexthop2, med2, localpref2, │ origin2, aspath2, nexthop2, med2, localpref2,
} │ }
nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:701 │ gobgp/internal/pkg/table/table_manager_test.go:424
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(1) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("::",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
│
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "::"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:863 │ gobgp/internal/pkg/table/table_manager_test.go:424
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(500) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("::",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
│
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "::"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1025 │ gobgp/internal/pkg/table/table_manager_test.go:424
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("::",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
│
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "::"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1190 │ gobgp/internal/pkg/table/table_manager_test.go:424
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("::",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer3 := peerR3() │ var peer2 *PeerInfo = &PeerInfo{
pList, err = tm.ProcessUpdate(peer3, bgpMessage2) │ Address: net.ParseIP("0.0.0.0"),
│ }
│
│ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "::"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:863 │ gobgp/internal/pkg/table/table_manager_test.go:701
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65200, 65000}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(500) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(200)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1025 │ gobgp/internal/pkg/table/table_manager_test.go:701
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(200)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1190 │ gobgp/internal/pkg/table/table_manager_test.go:701
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(200)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer3 := peerR3() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer3, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1025 │ gobgp/internal/pkg/table/table_manager_test.go:863
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(500)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1190 │ gobgp/internal/pkg/table/table_manager_test.go:863
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(500)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer3 := peerR3() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer3, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1190 │ gobgp/internal/pkg/table/table_manager_test.go:1025
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000, 65200}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65200}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65200})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(200) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(100) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer3 := peerR3() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer3, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:260 │ gobgp/internal/pkg/table/table_manager_test.go:424
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("::",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ var peer2 *PeerInfo = &PeerInfo{
│ Address: net.ParseIP("0.0.0.0"),
│ }
│
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "::"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:260 │ gobgp/internal/pkg/table/table_manager_test.go:701
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(1)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(100)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(100)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(200)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:260 │ gobgp/internal/pkg/table/table_manager_test.go:863
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65200, 65000})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(500)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:260 │ gobgp/internal/pkg/table/table_manager_test.go:1025
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65200})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:260 │ gobgp/internal/pkg/table/table_manager_test.go:1190
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
mp_reach1 := createMpReach("2001::192:168:50:1", │ mp_reach1 := createMpReach("2001::192:168:50:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med1 := bgp.NewPathAttributeMultiExitDisc(100) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
mp_reach1, origin1, aspath1, med1, localpref1, │ mp_reach1, origin1, aspath1, med1, localpref1,
} │ }
│
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nil)
│
origin2 := bgp.NewPathAttributeOrigin(0) │ origin2 := bgp.NewPathAttributeOrigin(0)
aspath2 := createAsPathAttribute([]uint32{65100, 65000}) │ aspath2 := createAsPathAttribute([]uint32{65100, 65200})
mp_reach2 := createMpReach("2001::192:168:100:1", │ mp_reach2 := createMpReach("2001::192:168:100:1",
[]bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")} │ []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::")}
med2 := bgp.NewPathAttributeMultiExitDisc(100) │ med2 := bgp.NewPathAttributeMultiExitDisc(200)
localpref2 := bgp.NewPathAttributeLocalPref(200) │ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes2 := []bgp.PathAttributeInterface{ │ pathAttributes2 := []bgp.PathAttributeInterface{
mp_reach2, origin2, aspath2, med2, localpref2, │ mp_reach2, origin2, aspath2, med2, localpref2,
} │ }
│
bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil) │ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nil)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
peer2 := peerR2() │ peer3 := peerR3()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer3, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 5, len(path.GetPathAttrs())) │ assert.Equal(t, 5, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:100:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:4716 │ gobgp/internal/pkg/config/bgp_configs.go:4671
│
// original -> bgp-mp:always-compare-med │ // original -> bgp-mp:always-compare-med
// bgp-mp:always-compare-med's original type is boolean. │ // bgp-mp:always-compare-med's original type is boolean.
// Compare multi-exit discriminator (MED) value from │ // Compare multi-exit discriminator (MED) value from
// different ASes when selecting the best route. The │ // different ASes when selecting the best route. The
// default behavior is to only compare MEDs for paths │ // default behavior is to only compare MEDs for paths
// received from the same AS. │ // received from the same AS.
AlwaysCompareMed bool `mapstructure:"always-compare-med" json:"always-compare-me │ AlwaysCompareMed bool `mapstructure:"always-compare-med" json:"always-compare-me
// original -> bgp-mp:ignore-as-path-length │ // original -> bgp-mp:ignore-as-path-length
// bgp-mp:ignore-as-path-length's original type is boolean. │ // bgp-mp:ignore-as-path-length's original type is boolean.
// Ignore the AS path length when selecting the best path. │ // Ignore the AS path length when selecting the best path.
// The default is to use the AS path length and prefer paths │ // The default is to use the AS path length and prefer paths
// with shorter length. │ // with shorter length.
IgnoreAsPathLength bool `mapstructure:"ignore-as-path-length" json:"ignore-as-pa │ IgnoreAsPathLength bool `mapstructure:"ignore-as-path-length" json:"ignore-as-pa
// original -> bgp-mp:external-compare-router-id │ // original -> bgp-mp:external-compare-router-id
// bgp-mp:external-compare-router-id's original type is boolean. │ // bgp-mp:external-compare-router-id's original type is boolean.
// When comparing similar routes received from external │ // When comparing similar routes received from external
// BGP peers, use the router-id as a criterion to select │ // BGP peers, use the router-id as a criterion to select
// the active path. │ // the active path.
ExternalCompareRouterId bool `mapstructure:"external-compare-router-id" json:"ex │ ExternalCompareRouterId bool `mapstructure:"external-compare-router-id" json:"ex
// original -> bgp-mp:advertise-inactive-routes │ // original -> bgp-mp:advertise-inactive-routes
// bgp-mp:advertise-inactive-routes's original type is boolean. │ // bgp-mp:advertise-inactive-routes's original type is boolean.
// Advertise inactive routes to external peers. The │ // Advertise inactive routes to external peers. The
// default is to only advertise active routes. │ // default is to only advertise active routes.
AdvertiseInactiveRoutes bool `mapstructure:"advertise-inactive-routes" json:"adv │ AdvertiseInactiveRoutes bool `mapstructure:"advertise-inactive-routes" json:"adv
// original -> bgp-mp:enable-aigp │ // original -> bgp-mp:enable-aigp
// bgp-mp:enable-aigp's original type is boolean. │ // bgp-mp:enable-aigp's original type is boolean.
// Flag to enable sending / receiving accumulated IGP │ // Flag to enable sending / receiving accumulated IGP
// attribute in routing updates. │ // attribute in routing updates.
EnableAigp bool `mapstructure:"enable-aigp" json:"enable-aigp,omitempty"` │ EnableAigp bool `mapstructure:"enable-aigp" json:"enable-aigp,omitempty"`
// original -> bgp-mp:ignore-next-hop-igp-metric │ // original -> bgp-mp:ignore-next-hop-igp-metric
// bgp-mp:ignore-next-hop-igp-metric's original type is boolean. │ // bgp-mp:ignore-next-hop-igp-metric's original type is boolean.
// Ignore the IGP metric to the next-hop when calculating │ // Ignore the IGP metric to the next-hop when calculating
// BGP best-path. The default is to select the route for │ // BGP best-path. The default is to select the route for
// which the metric to the next-hop is lowest. │ // which the metric to the next-hop is lowest.
IgnoreNextHopIgpMetric bool `mapstructure:"ignore-next-hop-igp-metric" json:"ign │ IgnoreNextHopIgpMetric bool `mapstructure:"ignore-next-hop-igp-metric" json:"ign
// original -> gobgp:disable-best-path-selection │ // original -> gobgp:disable-best-path-selection
// gobgp:disable-best-path-selection's original type is boolean. │ // gobgp:disable-best-path-selection's original type is boolean.
// Disables best path selection process. │ // Disables best path selection process.
DisableBestPathSelection bool `mapstructure:"disable-best-path-selection" json:" │ DisableBestPathSelection bool `mapstructure:"disable-best-path-selection" json:"
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1503 │ gobgp/internal/pkg/table/table_manager_test.go:945
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// path1 │ // low origin message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000, 65200})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(200)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// path 1 withdraw │ // high origin message
w1 := bgp.NewIPAddrPrefix(24, "10.10.10.0") │ origin2 := bgp.NewPathAttributeOrigin(0)
w := []*bgp.IPAddrPrefix{w1} │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
bgpMessage1_w := bgp.NewBGPUpdateMessage(w, nil, nil) │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.100.1")
│ med2 := bgp.NewPathAttributeMultiExitDisc(200)
│ localpref2 := bgp.NewPathAttributeLocalPref(100)
│
│ pathAttributes2 := []bgp.PathAttributeInterface{
│ origin2, aspath2, nexthop2, med2, localpref2,
│ }
│ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
│ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
pList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) │ peer2 := peerR2()
│ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, true) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check old best path │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
checkPattr := func(expected *bgp.BGPMessage, actual *Path) { │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes │ expectedOrigin := pathAttributes[0]
expectedOrigin := pathAttributes[0] │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │
│ expectedAsPath := pathAttributes[1]
expectedAsPath := pathAttributes[1] │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ assert.Equal(t, expectedAsPath, pathAspath)
assert.Equal(t, expectedAsPath, pathAspath) │
│ expectedNexthopAttr := pathAttributes[2]
expectedNexthopAttr := pathAttributes[2] │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │
│ expectedMed := pathAttributes[3]
expectedMed := pathAttributes[3] │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ assert.Equal(t, expectedMed, pathMed)
assert.Equal(t, expectedMed, pathMed) │
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
} │
│
checkPattr(bgpMessage1, path) │
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
│ // check nexthop
│ expectedNexthop := "192.168.100.1"
│ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:1503 │ gobgp/internal/pkg/table/table_manager_test.go:180
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
// path1 │ // low localpref message
origin1 := bgp.NewPathAttributeOrigin(0) │ origin1 := bgp.NewPathAttributeOrigin(0)
aspath1 := createAsPathAttribute([]uint32{65000}) │ aspath1 := createAsPathAttribute([]uint32{65000})
nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop1 := bgp.NewPathAttributeNextHop("192.168.50.1")
med1 := bgp.NewPathAttributeMultiExitDisc(200) │ med1 := bgp.NewPathAttributeMultiExitDisc(0)
localpref1 := bgp.NewPathAttributeLocalPref(100) │ localpref1 := bgp.NewPathAttributeLocalPref(100)
│
pathAttributes1 := []bgp.PathAttributeInterface{ │ pathAttributes1 := []bgp.PathAttributeInterface{
origin1, aspath1, nexthop1, med1, localpref1, │ origin1, aspath1, nexthop1, med1, localpref1,
} │ }
nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri1 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1) │ bgpMessage1 := bgp.NewBGPUpdateMessage(nil, pathAttributes1, nlri1)
│
// path 1 withdraw │ // high localpref message
w1 := bgp.NewIPAddrPrefix(24, "10.10.10.0") │ origin2 := bgp.NewPathAttributeOrigin(0)
w := []*bgp.IPAddrPrefix{w1} │ aspath2 := createAsPathAttribute([]uint32{65100, 65000})
bgpMessage1_w := bgp.NewBGPUpdateMessage(w, nil, nil) │ nexthop2 := bgp.NewPathAttributeNextHop("192.168.50.1")
│ med2 := bgp.NewPathAttributeMultiExitDisc(100)
│ localpref2 := bgp.NewPathAttributeLocalPref(200)
│
│ pathAttributes2 := []bgp.PathAttributeInterface{
│ origin2, aspath2, nexthop2, med2, localpref2,
│ }
│ nlri2 := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
│ bgpMessage2 := bgp.NewBGPUpdateMessage(nil, pathAttributes2, nlri2)
│
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
pList, err = tm.ProcessUpdate(peer1, bgpMessage1_w) │ peer2 := peerR2()
│ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, true) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check old best path │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
checkPattr := func(expected *bgp.BGPMessage, actual *Path) { │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
pathAttributes := expected.Body.(*bgp.BGPUpdate).PathAttributes │ expectedOrigin := pathAttributes[0]
expectedOrigin := pathAttributes[0] │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
attr := actual.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │
│ expectedAsPath := pathAttributes[1]
expectedAsPath := pathAttributes[1] │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ assert.Equal(t, expectedAsPath, pathAspath)
assert.Equal(t, expectedAsPath, pathAspath) │
│ expectedNexthopAttr := pathAttributes[2]
expectedNexthopAttr := pathAttributes[2] │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │
│ expectedMed := pathAttributes[3]
expectedMed := pathAttributes[3] │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
attr = actual.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ assert.Equal(t, expectedMed, pathMed)
assert.Equal(t, expectedMed, pathMed) │
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, len(pathAttributes), len(path.GetPathAttrs())) │ assert.Equal(t, len(pathAttributes2), len(path.GetPathAttrs()))
} │
│
checkPattr(bgpMessage1, path) │
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "10.10.10.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
│ // check nexthop
│ expectedNexthop := "192.168.50.1"
│ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:406 │ gobgp/pkg/packet/bgp/bgp_test.go:505
│
assert := assert.New(t) │
cmp := make([]FlowSpecComponentInterface, 0) │ cmp := make([]FlowSpecComponentInterface, 0)
cmp = append(cmp, NewFlowSpecDestinationPrefix(NewIPAddrPrefix(24, "10.0.0.0"))) │ cmp = append(cmp, NewFlowSpecDestinationPrefix6(NewIPv6AddrPrefix(64, "2001::"),
cmp = append(cmp, NewFlowSpecSourcePrefix(NewIPAddrPrefix(24, "10.0.0.0"))) │ cmp = append(cmp, NewFlowSpecSourcePrefix6(NewIPv6AddrPrefix(64, "2001::"), 12))
item1 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, TCP) │ item1 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, TCP)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_IP_PROTO, []*FlowSpecCompo │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_IP_PROTO, []*FlowSpecCompo
item2 := NewFlowSpecComponentItem(DEC_NUM_OP_GT_EQ, 20) │ item2 := NewFlowSpecComponentItem(DEC_NUM_OP_GT_EQ, 20)
item3 := NewFlowSpecComponentItem(DEC_NUM_OP_AND|DEC_NUM_OP_LT_EQ, 30) │ item3 := NewFlowSpecComponentItem(DEC_NUM_OP_AND|DEC_NUM_OP_LT_EQ, 30)
item4 := NewFlowSpecComponentItem(DEC_NUM_OP_GT_EQ, 10) │ item4 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, 10)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PORT, []*FlowSpecComponent │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PORT, []*FlowSpecComponent
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DST_PORT, []*FlowSpecCompo │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DST_PORT, []*FlowSpecCompo
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_SRC_PORT, []*FlowSpecCompo │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_SRC_PORT, []*FlowSpecCompo
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ICMP_TYPE, []*FlowSpecComp │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ICMP_TYPE, []*FlowSpecComp
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ICMP_CODE, []*FlowSpecComp │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ICMP_CODE, []*FlowSpecComp
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PKT_LEN, []*FlowSpecCompon │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PKT_LEN, []*FlowSpecCompon
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DSCP, []*FlowSpecComponent │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DSCP, []*FlowSpecComponent
│ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_LABEL, []*FlowSpecComponen
isFragment := uint64(0x02) │ isFragment := uint64(0x02)
lastFragment := uint64(0x08) │
item5 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_MATCH, isFragment) │ item5 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_MATCH, isFragment)
item6 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_AND, lastFragment) │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_FRAGMENT, []*FlowSpecCompo
│ item6 := NewFlowSpecComponentItem(0, TCP_FLAG_ACK)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_FRAGMENT, []*FlowSpecCompo │ item7 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_AND|BITMASK_FLAG_OP_NOT, TCP_F
item7 := NewFlowSpecComponentItem(0, TCP_FLAG_ACK) │ cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_TCP_FLAG, []*FlowSpecCompo
item8 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_AND|BITMASK_FLAG_OP_NOT, TCP_F │ n1 := NewFlowSpecIPv6Unicast(cmp)
│
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_TCP_FLAG, []*FlowSpecCompo │
n1 := NewFlowSpecIPv4Unicast(cmp) │
│
buf1, err := n1.Serialize() │ buf1, err := n1.Serialize()
assert.Nil(err) │ require.NoError(t, err)
│
n2, err := NewPrefixFromRouteFamily(RouteFamilyToAfiSafi(RF_FS_IPv4_UC)) │ n2, err := NewPrefixFromRouteFamily(RouteFamilyToAfiSafi(RF_FS_IPv6_UC))
assert.Nil(err) │ require.NoError(t, err)
│
err = n2.DecodeFromBytes(buf1) │ err = n2.DecodeFromBytes(buf1)
assert.Nil(err) │ require.NoError(t, err)
// should be equal │
assert.Equal(n1, n2) │ _, err = n2.Serialize()
│ require.NoError(t, err)
│
│ assert.Equal(t, n1, n2)
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:1769 │ gobgp/internal/pkg/config/bgp_configs.go:1719
│
// original -> bgp:peer-as │ // original -> bgp:peer-as
// bgp:peer-as's original type is inet:as-number. │ // bgp:peer-as's original type is inet:as-number.
// AS number of the peer. │ // AS number of the peer.
PeerAs uint32 `mapstructure:"peer-as" json:"peer-as,omitempty"` │ PeerAs uint32 `mapstructure:"peer-as" json:"peer-as,omitempty"`
// original -> bgp:local-as │ // original -> bgp:local-as
// bgp:local-as's original type is inet:as-number. │ // bgp:local-as's original type is inet:as-number.
// The local autonomous system number that is to be used │ // The local autonomous system number that is to be used
// when establishing sessions with the remote peer or peer │ // when establishing sessions with the remote peer or peer
// group, if this differs from the global BGP router │ // group, if this differs from the global BGP router
// autonomous system number. │ // autonomous system number.
LocalAs uint32 `mapstructure:"local-as" json:"local-as,omitempty"` │ LocalAs uint32 `mapstructure:"local-as" json:"local-as,omitempty"`
// original -> bgp:peer-type │ // original -> bgp:peer-type
// Explicitly designate the peer or peer group as internal │ // Explicitly designate the peer or peer group as internal
// (iBGP) or external (eBGP). │ // (iBGP) or external (eBGP).
PeerType PeerType `mapstructure:"peer-type" json:"peer-type,omitempty"` │ PeerType PeerType `mapstructure:"peer-type" json:"peer-type,omitempty"`
// original -> bgp:auth-password │ // original -> bgp:auth-password
// Configures an MD5 authentication password for use with │ // Configures an MD5 authentication password for use with
// neighboring devices. │ // neighboring devices.
AuthPassword string `mapstructure:"auth-password" json:"auth-password,omitempty" │ AuthPassword string `mapstructure:"auth-password" json:"auth-password,omitempty"
// original -> bgp:remove-private-as │ // original -> bgp:remove-private-as
// Remove private AS numbers from updates sent to peers. │ // Remove private AS numbers from updates sent to peers.
RemovePrivateAs RemovePrivateAsOption `mapstructure:"remove-private-as" json:"re │ RemovePrivateAs RemovePrivateAsOption `mapstructure:"remove-private-as" json:"re
// original -> bgp:route-flap-damping │ // original -> bgp:route-flap-damping
// bgp:route-flap-damping's original type is boolean. │ // bgp:route-flap-damping's original type is boolean.
// Enable route flap damping. │ // Enable route flap damping.
RouteFlapDamping bool `mapstructure:"route-flap-damping" json:"route-flap-dampin │ RouteFlapDamping bool `mapstructure:"route-flap-damping" json:"route-flap-dampin
// original -> bgp:send-community │ // original -> bgp:send-community
// Specify which types of community should be sent to the │ // Specify which types of community should be sent to the
// neighbor or group. The default is to not send the │ // neighbor or group. The default is to not send the
// community attribute. │ // community attribute.
SendCommunity CommunityType `mapstructure:"send-community" json:"send-community, │ SendCommunity CommunityType `mapstructure:"send-community" json:"send-community,
// original -> bgp:description │ // original -> bgp:description
// An optional textual description (intended primarily for use │ // An optional textual description (intended primarily for use
// with a peer or group. │ // with a peer or group.
Description string `mapstructure:"description" json:"description,omitempty"` │ Description string `mapstructure:"description" json:"description,omitempty"`
// original -> bgp:peer-group-name │ // original -> bgp:peer-group-name
// Name of the BGP peer-group. │ // Name of the BGP peer-group.
PeerGroupName string `mapstructure:"peer-group-name" json:"peer-group-name,omite │ PeerGroupName string `mapstructure:"peer-group-name" json:"peer-group-name,omite
│ // original -> bgp-op:total-paths
│ // Total number of BGP paths within the context.
│ TotalPaths uint32 `mapstructure:"total-paths" json:"total-paths,omitempty"`
│ // original -> bgp-op:total-prefixes
│ // .
│ TotalPrefixes uint32 `mapstructure:"total-prefixes" json:"total-prefixes,omitemp
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:2931 │ gobgp/internal/pkg/config/bgp_configs.go:2851
│
// original -> bgp-op:UPDATE │ // original -> bgp-op:UPDATE
// Number of BGP UPDATE messages announcing, withdrawing │ // Number of BGP UPDATE messages announcing, withdrawing
// or modifying paths exchanged. │ // or modifying paths exchanged.
Update uint64 `mapstructure:"update" json:"update,omitempty"` │ Update uint64 `mapstructure:"update" json:"update,omitempty"`
// original -> bgp-op:NOTIFICATION │ // original -> bgp-op:NOTIFICATION
// Number of BGP NOTIFICATION messages indicating an │ // Number of BGP NOTIFICATION messages indicating an
// error condition has occurred exchanged. │ // error condition has occurred exchanged.
Notification uint64 `mapstructure:"notification" json:"notification,omitempty"` │ Notification uint64 `mapstructure:"notification" json:"notification,omitempty"`
// original -> gobgp:OPEN │ // original -> gobgp:OPEN
// Number of BGP open messages announcing, withdrawing │ // Number of BGP open messages announcing, withdrawing
// or modifying paths exchanged. │ // or modifying paths exchanged.
Open uint64 `mapstructure:"open" json:"open,omitempty"` │ Open uint64 `mapstructure:"open" json:"open,omitempty"`
// original -> gobgp:REFRESH │ // original -> gobgp:REFRESH
// Number of BGP Route-Refresh messages indicating an │ // Number of BGP Route-Refresh messages indicating an
// error condition has occurred exchanged. │ // error condition has occurred exchanged.
Refresh uint64 `mapstructure:"refresh" json:"refresh,omitempty"` │ Refresh uint64 `mapstructure:"refresh" json:"refresh,omitempty"`
// original -> gobgp:KEEPALIVE │ // original -> gobgp:KEEPALIVE
// Number of BGP Keepalive messages indicating an │ // Number of BGP Keepalive messages indicating an
// error condition has occurred exchanged. │ // error condition has occurred exchanged.
Keepalive uint64 `mapstructure:"keepalive" json:"keepalive,omitempty"` │ Keepalive uint64 `mapstructure:"keepalive" json:"keepalive,omitempty"`
// original -> gobgp:DYNAMIC-CAP │ // original -> gobgp:DYNAMIC-CAP
// Number of BGP dynamic-cap messages indicating an │ // Number of BGP dynamic-cap messages indicating an
// error condition has occurred exchanged. │ // error condition has occurred exchanged.
DynamicCap uint64 `mapstructure:"dynamic-cap" json:"dynamic-cap,omitempty"` │ DynamicCap uint64 `mapstructure:"dynamic-cap" json:"dynamic-cap,omitempty"`
// original -> gobgp:WITHDRAW-UPDATE │ // original -> gobgp:WITHDRAW-UPDATE
// Number of updates subjected to treat-as-withdraw treatment. │ // Number of updates subjected to treat-as-withdraw treatment.
WithdrawUpdate uint32 `mapstructure:"withdraw-update" json:"withdraw-update,omit │ WithdrawUpdate uint32 `mapstructure:"withdraw-update" json:"withdraw-update,omit
// original -> gobgp:WITHDRAW-PREFIX │ // original -> gobgp:WITHDRAW-PREFIX
// Number of prefixes subjected to treat-as-withdraw treatment. │ // Number of prefixes subjected to treat-as-withdraw treatment.
WithdrawPrefix uint32 `mapstructure:"withdraw-prefix" json:"withdraw-prefix,omit │ WithdrawPrefix uint32 `mapstructure:"withdraw-prefix" json:"withdraw-prefix,omit
// original -> gobgp:DISCARDED │ // original -> gobgp:DISCARDED
// Number of discarded messages indicating an │ // Number of discarded messages indicating an
// error condition has occurred exchanged. │ // error condition has occurred exchanged.
Discarded uint64 `mapstructure:"discarded" json:"discarded,omitempty"` │ Discarded uint64 `mapstructure:"discarded" json:"discarded,omitempty"`
// original -> gobgp:TOTAL │ // original -> gobgp:TOTAL
// Number of total messages indicating an │ // Number of total messages indicating an
// error condition has occurred exchanged. │ // error condition has occurred exchanged.
Total uint64 `mapstructure:"total" json:"total,omitempty"` │ Total uint64 `mapstructure:"total" json:"total,omitempty"`
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:3179 │ gobgp/pkg/packet/bgp/bgp_test.go:3162
[]byte{ │ []byte{
// LS Attribute with all Node-related TLVs. │ // LS Attribute with all Node-related TLVs.
0x80, 0x29, 0x5d, // Optional attribute, BGP_ATTR_TYPE_LS, corre │ 0x80, 0x29, 0x62, // Optional attribute, BGP_ATTR_TYPE_LS, corre
0x04, 0x00, 0x00, 0x01, 0xFF, // Node flags (all set) │ 0x04, 0x00, 0x00, 0x01, 0xFF, // Node flags (all set)
0x04, 0x01, 0x00, 0x03, 0x01, 0x02, 0x03, // Opaque Node Attr [1 │ 0x04, 0x01, 0x00, 0x03, 0x01, 0x02, 0x03, // Opaque Node Attr [1
0x04, 0x02, 0x00, 0x03, 0x72, 0x74, 0x72, // Node name: "rtr" │ 0x04, 0x02, 0x00, 0x03, 0x72, 0x74, 0x72, // Node name: "rtr"
0x04, 0x03, 0x00, 0x03, 0x72, 0x74, 0x72, // ISIS area: [114 116 │ 0x04, 0x03, 0x00, 0x03, 0x72, 0x74, 0x72, // ISIS area: [114 116
0x04, 0x04, 0x00, 0x04, 0x01, 0x01, 0x01, 0x01, // Local RouterI │ 0x04, 0x04, 0x00, 0x04, 0x01, 0x01, 0x01, 0x01, // Local RouterI
0x04, 0x05, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00 │ 0x04, 0x05, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
0x04, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x88, 0xb8, 0x04, 0x89 │ 0x04, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x88, 0xb8, 0x04, 0x89
0x04, 0x0b, 0x00, 0x03, 0x01, 0x02, 0x03, // SR Algorithm [1 2 3 │ 0x04, 0x0b, 0x00, 0x03, 0x01, 0x02, 0x03, // SR ALgorithm [1 2 3
0x04, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x88, 0xb8, 0x04, 0x89 │ 0x04, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x88, 0xb8, 0x04, 0x89
│ 0xde, 0xad, 0x00, 0x01, 0xFF, // Unknown TLV
}, │ },
"{LsAttributes: {Node Flags: XXVRBETO} {Opaque attribute: [1 2 3 │ "{LsAttributes: {Node Flags: XXVRBETO} {Opaque attribute: [1 2 3
`{"type":41,"flags":128,"node":{"flags":{"overload":true,"attach │ `{"type":41,"flags":128,"node":{"flags":{"overload":true,"attach
true, false} │ false, false
next prev up gobgp/internal/pkg/table/policy_test.go:325 │ gobgp/internal/pkg/table/policy_test.go:372
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.1.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.1.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.1.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.1.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.1.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.1.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path1 := ProcessMessage(updateMsg, peer, time.Now())[0] │ path1 := ProcessMessage(updateMsg, peer, time.Now())[0]
│
peer = &PeerInfo{AS: 65002, Address: net.ParseIP("10.0.2.2")} │ peer = &PeerInfo{AS: 65002, Address: net.ParseIP("10.0.2.2")}
origin = bgp.NewPathAttributeOrigin(0) │ origin = bgp.NewPathAttributeOrigin(0)
aspathParam = []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002})} │ aspathParam = []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002})}
aspath = bgp.NewPathAttributeAsPath(aspathParam) │ aspath = bgp.NewPathAttributeAsPath(aspathParam)
nexthop = bgp.NewPathAttributeNextHop("10.0.2.2") │ nexthop = bgp.NewPathAttributeNextHop("10.0.2.2")
med = bgp.NewPathAttributeMultiExitDisc(0) │ med = bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes = []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes = []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri = []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.9.2.102")} │ nlri = []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.2.102")}
updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path2 := ProcessMessage(updateMsg, peer, time.Now())[0] │ path2 := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") │ ns := createNeighborSet("ns1", "10.0.1.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "", false) │ s := createStatement("statement1", "", "ns1", false)
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ pType, newPath := r.policyMap["pd1"].Apply(logger, path1, nil)
pType, newPath := p.Apply(logger, path1, nil) │
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path1) │ assert.Equal(t, newPath, path1)
│
pType2, newPath2 := p.Apply(logger, path2, nil) │ pType2, newPath2 := r.policyMap["pd1"].Apply(logger, path2, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType2) │ assert.Equal(t, ROUTE_TYPE_NONE, pType2)
assert.Equal(t, newPath2, path2) │ assert.Equal(t, newPath2, path2)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2713 │ gobgp/internal/pkg/table/policy_test.go:2656
│
│
assert := assert.New(t) │ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAs4PathParam(2, []uint32{ │ bgp.NewAs4PathParam(2, []uint32{
createAs4Value("65002.1"), │
createAs4Value("65001.1"), │ createAs4Value("65001.1"),
createAs4Value("65000.1"), │ createAs4Value("65000.1"),
}), │ }),
} │ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
body := updateMsg.Body.(*bgp.BGPUpdate) │ body := updateMsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, body) │ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetAsPathPrepend.As = "last-as" │ s.Actions.BgpActions.SetAsPathPrepend.As = fmt.Sprintf("%d", createAs4Value("650
s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5 │ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
r.reload(pl) │ r.reload(pl)
p, _ := NewPolicy(pl.PolicyDefinitions[0]) │ p, err := NewPolicy(pl.PolicyDefinitions[0])
│ assert.Nil(err)
addPolicy(r, p) │ addPolicy(r, p)
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath) │ assert.NotEqual(nil, newPath)
asn := createAs4Value("65002.1") │ asn := createAs4Value("65002.1")
assert.Equal([]uint32{ │ assert.Equal([]uint32{
asn, asn, asn, asn, asn, │ asn, asn, asn, asn, asn, asn, asn, asn, asn, asn,
createAs4Value("65002.1"), │
createAs4Value("65001.1"), │ createAs4Value("65001.1"),
createAs4Value("65000.1"), │ createAs4Value("65000.1"),
}, newPath.GetAsSeqList()) │ }, newPath.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:509 │ gobgp/internal/pkg/table/table_manager_test.go:564
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
bgpMessage1 := update_fromR2viaR1() │ bgpMessage1 := update_fromR2viaR1_ipv6()
peer1 := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer1, bgpMessage1) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
bgpMessage2 := update_fromR2() │ bgpMessage2 := update_fromR2_ipv6()
peer2 := peerR2() │ peer2 := peerR2()
pList, err = tm.ProcessUpdate(peer2, bgpMessage2) │ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedNexthopAttr := pathAttributes[0]
│ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
│ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
│ expectedOrigin := pathAttributes[1]
│ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │
pathNexthop := attr.(*bgp.PathAttributeNextHop) │
assert.Equal(t, expectedNexthopAttr, pathNexthop) │
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 4, len(path.GetPathAttrs())) │ assert.Equal(t, 4, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "20.20.20.0/24" │ expectedPrefix := "2002:223:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.100.1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:3846 │ gobgp/internal/pkg/config/bgp_configs.go:3812
│
// original -> rpol:import-policy │ // original -> rpol:import-policy
// list of policy names in sequence to be applied on │ // list of policy names in sequence to be applied on
// receiving a routing update in the current context, e.g., │ // receiving a routing update in the current context, e.g.,
// for the current peer group, neighbor, address family, │ // for the current peer group, neighbor, address family,
// etc. │ // etc.
ImportPolicyList []string `mapstructure:"import-policy-list" json:"import-policy │ ImportPolicyList []string `mapstructure:"import-policy-list" json:"import-policy
// original -> rpol:default-import-policy │ // original -> rpol:default-import-policy
// explicitly set a default policy if no policy definition │ // explicitly set a default policy if no policy definition
// in the import policy chain is satisfied. │ // in the import policy chain is satisfied.
DefaultImportPolicy DefaultPolicyType `mapstructure:"default-import-policy" json │ DefaultImportPolicy DefaultPolicyType `mapstructure:"default-import-policy" json
// original -> rpol:export-policy │ // original -> rpol:export-policy
// list of policy names in sequence to be applied on │ // list of policy names in sequence to be applied on
// sending a routing update in the current context, e.g., │ // sending a routing update in the current context, e.g.,
// for the current peer group, neighbor, address family, │ // for the current peer group, neighbor, address family,
// etc. │ // etc.
ExportPolicyList []string `mapstructure:"export-policy-list" json:"export-policy │ ExportPolicyList []string `mapstructure:"export-policy-list" json:"export-policy
// original -> rpol:default-export-policy │ // original -> rpol:default-export-policy
// explicitly set a default policy if no policy definition │ // explicitly set a default policy if no policy definition
// in the export policy chain is satisfied. │ // in the export policy chain is satisfied.
DefaultExportPolicy DefaultPolicyType `mapstructure:"default-export-policy" json │ DefaultExportPolicy DefaultPolicyType `mapstructure:"default-export-policy" json
// original -> gobgp:in-policy │ // original -> gobgp:in-policy
// list of policy names in sequence to be applied on │ // list of policy names in sequence to be applied on
// sending a routing update in the current context, e.g., │ // sending a routing update in the current context, e.g.,
// for the current other route server clients. │ // for the current other route server clients.
InPolicyList []string `mapstructure:"in-policy-list" json:"in-policy-list,omitem │ InPolicyList []string `mapstructure:"in-policy-list" json:"in-policy-list,omitem
// original -> gobgp:default-in-policy │ // original -> gobgp:default-in-policy
// explicitly set a default policy if no policy definition │ // explicitly set a default policy if no policy definition
// in the in-policy chain is satisfied. │ // in the in-policy chain is satisfied.
DefaultInPolicy DefaultPolicyType `mapstructure:"default-in-policy" json:"defaul │ DefaultInPolicy DefaultPolicyType `mapstructure:"default-in-policy" json:"defaul
} │
next prev up gobgp/internal/pkg/table/message_test.go:141 │ gobgp/internal/pkg/table/message_test.go:106
│
as1 := []uint16{65000, 4000} │ as1 := []uint16{65000, 4000}
param1 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1) │ param1 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1)
as2 := []uint16{10, 20, 30} │ as2 := []uint16{10, 20, 30}
param2 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as2) │ param2 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as2)
as3 := []uint16{bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as3 := []uint16{bgp.AS_TRANS, bgp.AS_TRANS, 40001}
param3 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as3) │ param3 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as3)
params := []bgp.AsPathParamInterface{param1, param2, param3} │ params := []bgp.AsPathParamInterface{param1, param2, param3}
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{3000, 400000, 300000, 40001} │ as4 := []uint32{400000, 300000, 40001}
param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, │ param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ,
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 3)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[2].(*
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[2].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[2].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[2].(*bgp.
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:1028 │ gobgp/pkg/apiutil/attribute_test.go:895
│
assert := assert.New(t) │ assert := assert.New(t)
│
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 1, // Destination Prefix │ Type: 1, // Destination Prefix
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:1::", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 2, // Source Prefix │ Type: 2, // Source Prefix
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:2::", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // Next Header │ Type: 3, // IP Protocol
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.VPNFlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
Rd: rd, │ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_VPN, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1895 │ gobgp/internal/pkg/table/policy_test.go:1849
│
│
// create path │ // create path
community1 := "0:1" │ community1 := "65000:100"
community2 := "10:1" │ community2 := "65000:200"
community3 := "45686:2" │ community3 := "65100:100"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue(community1), │ stringToCommunityValue(community1),
stringToCommunityValue(community2), │ stringToCommunityValue(community2),
stringToCommunityValue(community3), │ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", "^(0|45686):[0- │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", ".*:100")
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1941 │ gobgp/internal/pkg/table/policy_test.go:1849
│
│
// create path │ // create path
community1 := "65000:100" │ community1 := "65000:100"
community2 := "65000:200" │ community2 := "65000:200"
│ community3 := "65100:100"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue(community1), │ stringToCommunityValue(community1),
stringToCommunityValue(community2), │ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
// action NULL is obsolate │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", ".*:100")
s.Actions.BgpActions.SetCommunity.Options = "REPLACE" │
s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList = nil │
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
//assert.Equal(t, []uint32{}, newPath.GetCommunities()) │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1941 │ gobgp/internal/pkg/table/policy_test.go:1895
│
│
// create path │ // create path
community1 := "65000:100" │ community1 := "0:1"
community2 := "65000:200" │ community2 := "10:1"
│ community3 := "45686:2"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue(community1), │ stringToCommunityValue(community1),
stringToCommunityValue(community2), │ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
// action NULL is obsolate │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", "^(0|45686):[0-
s.Actions.BgpActions.SetCommunity.Options = "REPLACE" │
s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList = nil │
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
//assert.Equal(t, []uint32{}, newPath.GetCommunities()) │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1041 │ gobgp/internal/pkg/table/policy_test.go:1330
│
│
// setup │ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}), │ bgp.NewAs4PathParam(1, []uint32{
bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}), │ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ }),
│ bgp.NewAs4PathParam(2, []uint32{
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ }),
} │ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate)) │ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
asPathSet := config.AsPathSet{ │ asPathSet := config.AsPathSet{
AsPathSetName: "asset1", │ AsPathSetName: "asset1",
AsPathList: []string{"65005$"}, │ AsPathList: []string{fmt.Sprintf("%d$", createAs4Value("65005.1"))},
} │ }
│
ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
ds.BgpDefinedSets.AsPathSets = []config.AsPathSet{asPathSet} │ ds.BgpDefinedSets.AsPathSets = []config.AsPathSet{asPathSet}
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", false)
s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1" │ s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1"
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p, _ := NewPolicy(pl.PolicyDefinitions[0])
p := r.policyMap["pd1"] │ addPolicy(r, p)
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
│
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:1098 │ gobgp/pkg/apiutil/attribute_test.go:895
│
assert := assert.New(t) │ assert := assert.New(t)
│
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecMAC{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 15, // Source MAC │ Type: 1, // Destination Prefix
Address: "aa:bb:cc:11:22:33", │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecMAC{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 16, // Destination MAC │ Type: 2, // Source Prefix
Address: "dd:ee:ff:11:22:33", │ PrefixLen: 24,
│ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 21, // VLAN ID │ Type: 3, // IP Protocol
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 100, │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.VPNFlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
Rd: rd, │ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_VPN, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:1098 │ gobgp/pkg/apiutil/attribute_test.go:1028
│
assert := assert.New(t) │ assert := assert.New(t)
│
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecMAC{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 15, // Source MAC │ Type: 1, // Destination Prefix
Address: "aa:bb:cc:11:22:33", │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecMAC{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 16, // Destination MAC │ Type: 2, // Source Prefix
Address: "dd:ee:ff:11:22:33", │ PrefixLen: 64,
│ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 21, // VLAN ID │ Type: 3, // Next Header
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 100, │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.VPNFlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
Rd: rd, │ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_FLOW_SPEC_VPN, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1805 │ gobgp/internal/pkg/table/policy_test.go:1849
│
│
// create path │ // create path
community1 := "65000:100" │ community1 := "65000:100"
community2 := "65000:200" │ community2 := "65000:200"
│ community3 := "65100:100"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue(community1), │ stringToCommunityValue(community1),
stringToCommunityValue(community2), │ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", ".*:100")
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1805 │ gobgp/internal/pkg/table/policy_test.go:1895
│
│
// create path │ // create path
community1 := "65000:100" │ community1 := "0:1"
community2 := "65000:200" │ community2 := "10:1"
│ community3 := "45686:2"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue(community1), │ stringToCommunityValue(community1),
stringToCommunityValue(community2), │ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", "^(0|45686):[0-
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1805 │ gobgp/internal/pkg/table/policy_test.go:1941
│
│
// create path │ // create path
community1 := "65000:100" │ community1 := "65000:100"
community2 := "65000:200" │ community2 := "65000:200"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue(community1), │ stringToCommunityValue(community1),
stringToCommunityValue(community2), │ stringToCommunityValue(community2),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1) │ // action NULL is obsolate
│ s.Actions.BgpActions.SetCommunity.Options = "REPLACE"
│ s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList = nil
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni │ //assert.Equal(t, []uint32{}, newPath.GetCommunities())
} │
next prev up gobgp/internal/pkg/table/policy_test.go:585 │ gobgp/internal/pkg/table/policy_test.go:700
│
// setup │ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}), │ bgp.NewAs4PathParam(2, []uint32{
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}), │ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ }),
│ bgp.NewAs4PathParam(1, []uint32{
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ }),
} │ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate)) │ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
// create match condition │ // create match condition
asPathLength := config.AsPathLength{ │ asPathLength := config.AsPathLength{
Operator: "le", │ Operator: "le",
Value: 10, │ Value: 10,
} │ }
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", false)
s.Conditions.BgpConditions.AsPathLength = asPathLength │ s.Conditions.BgpConditions.AsPathLength = asPathLength
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p, _ := NewPolicy(pl.PolicyDefinitions[0])
p := r.policyMap["pd1"] │ addPolicy(r, p)
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
│
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:832 │ gobgp/pkg/apiutil/attribute_test.go:895
│
assert := assert.New(t) │ assert := assert.New(t)
│
│ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
│ Admin: "1.1.1.1",
│ Assigned: 100,
│ })
│ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 1, // Destination Prefix │ Type: 1, // Destination Prefix
PrefixLen: 24, │ PrefixLen: 24,
Prefix: "192.168.101.0", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 2, // Source Prefix │ Type: 2, // Source Prefix
PrefixLen: 24, │ PrefixLen: 24,
Prefix: "192.168.201.0", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // IP Protocol │ Type: 3, // IP Protocol
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.FlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
│ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:832 │ gobgp/pkg/apiutil/attribute_test.go:1028
│
assert := assert.New(t) │ assert := assert.New(t)
│
│ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
│ Admin: "1.1.1.1",
│ Assigned: 100,
│ })
│ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 1, // Destination Prefix │ Type: 1, // Destination Prefix
PrefixLen: 24, │ PrefixLen: 64,
Prefix: "192.168.101.0", │ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 2, // Source Prefix │ Type: 2, // Source Prefix
PrefixLen: 24, │ PrefixLen: 64,
Prefix: "192.168.201.0", │ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // IP Protocol │ Type: 3, // Next Header
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.FlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
│ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2567 │ gobgp/internal/pkg/table/policy_test.go:2656
│
│
assert := assert.New(t) │ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001, │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAs4PathParam(2, []uint32{
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
body := updateMsg.Body.(*bgp.BGPUpdate) │ body := updateMsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, body) │ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetAsPathPrepend.As = "65002" │ s.Actions.BgpActions.SetAsPathPrepend.As = fmt.Sprintf("%d", createAs4Value("650
s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10 │ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
r.reload(pl) │ r.reload(pl)
p := r.policyMap["pd1"] │ p, err := NewPolicy(pl.PolicyDefinitions[0])
│ assert.Nil(err)
│ addPolicy(r, p)
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath) │ assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65 │ asn := createAs4Value("65002.1")
│ assert.Equal([]uint32{
│ asn, asn, asn, asn, asn, asn, asn, asn, asn, asn,
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }, newPath.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2567 │ gobgp/internal/pkg/table/policy_test.go:2713
│
│
assert := assert.New(t) │ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001, │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAs4PathParam(2, []uint32{
│ createAs4Value("65002.1"),
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
body := updateMsg.Body.(*bgp.BGPUpdate) │ body := updateMsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, body) │ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetAsPathPrepend.As = "65002" │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10 │ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
r.reload(pl) │ r.reload(pl)
p := r.policyMap["pd1"] │ p, _ := NewPolicy(pl.PolicyDefinitions[0])
│ addPolicy(r, p)
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath) │ assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65 │ asn := createAs4Value("65002.1")
│ assert.Equal([]uint32{
│ asn, asn, asn, asn, asn,
│ createAs4Value("65002.1"),
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }, newPath.GetAsSeqList())
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:965 │ gobgp/pkg/apiutil/attribute_test.go:895
│
assert := assert.New(t) │ assert := assert.New(t)
│
│ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
│ Admin: "1.1.1.1",
│ Assigned: 100,
│ })
│ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 1, // Destination Prefix │ Type: 1, // Destination Prefix
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:1::", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 2, // Source Prefix │ Type: 2, // Source Prefix
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:2::", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // Next Header │ Type: 3, // IP Protocol
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.FlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
│ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:965 │ gobgp/pkg/apiutil/attribute_test.go:1028
│
assert := assert.New(t) │ assert := assert.New(t)
│
│ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
│ Admin: "1.1.1.1",
│ Assigned: 100,
│ })
│ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 1, // Destination Prefix │ Type: 1, // Destination Prefix
PrefixLen: 64, │ PrefixLen: 64,
Prefix: "2001:db8:1::", │ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 2, // Source Prefix │ Type: 2, // Source Prefix
PrefixLen: 64, │ PrefixLen: 64,
Prefix: "2001:db8:2::", │ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // Next Header │ Type: 3, // Next Header
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.FlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
│ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:965 │ gobgp/pkg/apiutil/attribute_test.go:1098
│
assert := assert.New(t) │ assert := assert.New(t)
│
│ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
│ Admin: "1.1.1.1",
│ Assigned: 100,
│ })
│ assert.Nil(err)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecMAC{
Type: 1, // Destination Prefix │ Type: 15, // Source MAC
PrefixLen: 64, │ Address: "aa:bb:cc:11:22:33",
Prefix: "2001:db8:1::", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecMAC{
Type: 2, // Source Prefix │ Type: 16, // Destination MAC
PrefixLen: 64, │ Address: "dd:ee:ff:11:22:33",
Prefix: "2001:db8:2::", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // Next Header │ Type: 21, // VLAN ID
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 100,
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.FlowSpecNLRI{ │ a, err := apb.New(&api.VPNFlowSpecNLRI{
│ Rd: rd,
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST, │ Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:965 │ gobgp/pkg/apiutil/attribute_test.go:832
│
assert := assert.New(t) │ assert := assert.New(t)
│
rules := make([]*apb.Any, 0, 3) │ rules := make([]*apb.Any, 0, 3)
rule, err := apb.New(&api.FlowSpecIPPrefix{ │ rule, err := apb.New(&api.FlowSpecIPPrefix{
Type: 1, // Destination Prefix │ Type: 1, // Destination Prefix
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:1::", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecIPPrefix{ │ rule, err = apb.New(&api.FlowSpecIPPrefix{
Type: 2, // Source Prefix │ Type: 2, // Source Prefix
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:2::", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
rule, err = apb.New(&api.FlowSpecComponent{ │ rule, err = apb.New(&api.FlowSpecComponent{
Type: 3, // Next Header │ Type: 3, // IP Protocol
Items: []*api.FlowSpecComponentItem{ │ Items: []*api.FlowSpecComponentItem{
{ │ {
Op: 0x80 | 0x01, // End, EQ │ Op: 0x80 | 0x01, // End, EQ
Value: 6, // TCP │ Value: 6, // TCP
}, │ },
}, │ },
}) │ })
assert.Nil(err) │ assert.Nil(err)
rules = append(rules, rule) │ rules = append(rules, rule)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.FlowSpecNLRI{ │ a, err := apb.New(&api.FlowSpecNLRI{
Rules: rules, │ Rules: rules,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST, │ Safi: api.Family_SAFI_FLOW_SPEC_UNICAST,
}, │ },
// NextHops: // No nexthop required │ // NextHops: // No nexthop required
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:129 │ gobgp/internal/pkg/table/table_manager_test.go:564
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
bgpMessage := update_fromR1_ipv6() │ bgpMessage1 := update_fromR2viaR1_ipv6()
peer := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer, bgpMessage) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
│ assert.Equal(t, 1, len(pList))
│ assert.Equal(t, pList[0].IsWithdraw, false)
│ assert.NoError(t, err)
│ bgpMessage2 := update_fromR2_ipv6()
│ peer2 := peerR2()
│ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
assert.Equal(t, 1, len(pList)) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
│
expectedNexthopAttr := pathAttributes[0] │ expectedNexthopAttr := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI) │ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedOrigin := pathAttributes[1] │ expectedOrigin := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[2] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 4, len(path.GetPathAttrs())) │ assert.Equal(t, 4, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "2001:123:123:1::/64" │ expectedPrefix := "2002:223:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "2001::192:168:50:1" │ expectedNexthop := "2001::192:168:100:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1761 │ gobgp/internal/pkg/table/policy_test.go:1849
│
│
// create path │ // create path
│ community1 := "65000:100"
│ community2 := "65000:200"
│ community3 := "65100:100"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue("65001:200"), │ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REPLACE", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", ".*:100")
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1761 │ gobgp/internal/pkg/table/policy_test.go:1895
│
│
// create path │ // create path
│ community1 := "0:1"
│ community2 := "10:1"
│ community3 := "45686:2"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue("65001:200"), │ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REPLACE", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", "^(0|45686):[0-
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1761 │ gobgp/internal/pkg/table/policy_test.go:1941
│
│
// create path │ // create path
│ community1 := "65000:100"
│ community2 := "65000:200"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue("65001:200"), │ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REPLACE", community) │ // action NULL is obsolate
│ s.Actions.BgpActions.SetCommunity.Options = "REPLACE"
│ s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList = nil
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ //assert.Equal(t, []uint32{}, newPath.GetCommunities())
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1761 │ gobgp/internal/pkg/table/policy_test.go:1805
│
│
// create path │ // create path
│ community1 := "65000:100"
│ community2 := "65000:200"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
communities := bgp.NewPathAttributeCommunities([]uint32{ │ communities := bgp.NewPathAttributeCommunities([]uint32{
stringToCommunityValue("65001:200"), │ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
}) │ })
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("REPLACE", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2612 │ gobgp/internal/pkg/table/policy_test.go:2656
│
│
assert := assert.New(t) │ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002, │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAs4PathParam(2, []uint32{
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
body := updateMsg.Body.(*bgp.BGPUpdate) │ body := updateMsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, body) │ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetAsPathPrepend.As = "last-as" │ s.Actions.BgpActions.SetAsPathPrepend.As = fmt.Sprintf("%d", createAs4Value("650
s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5 │ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
r.reload(pl) │ r.reload(pl)
p := r.policyMap["pd1"] │ p, err := NewPolicy(pl.PolicyDefinitions[0])
│ assert.Nil(err)
│ addPolicy(r, p)
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath) │ assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n │ asn := createAs4Value("65002.1")
│ assert.Equal([]uint32{
│ asn, asn, asn, asn, asn, asn, asn, asn, asn, asn,
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }, newPath.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2612 │ gobgp/internal/pkg/table/policy_test.go:2713
│
│
assert := assert.New(t) │ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002, │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAs4PathParam(2, []uint32{
│ createAs4Value("65002.1"),
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
body := updateMsg.Body.(*bgp.BGPUpdate) │ body := updateMsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, body) │ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetAsPathPrepend.As = "last-as" │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5 │ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
r.reload(pl) │ r.reload(pl)
p := r.policyMap["pd1"] │ p, _ := NewPolicy(pl.PolicyDefinitions[0])
│ addPolicy(r, p)
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath) │ assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n │ asn := createAs4Value("65002.1")
│ assert.Equal([]uint32{
│ asn, asn, asn, asn, asn,
│ createAs4Value("65002.1"),
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ }, newPath.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2612 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
assert := assert.New(t) │ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002, │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
body := updateMsg.Body.(*bgp.BGPUpdate) │ body := updateMsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, body) │ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetAsPathPrepend.As = "last-as" │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5 │ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
r.reload(pl) │ r.reload(pl)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(nil, newPath) │ assert.NotEqual(nil, newPath)
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n │ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:79 │ gobgp/internal/pkg/table/table_manager_test.go:509
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC})
│
bgpMessage := update_fromR1() │ bgpMessage1 := update_fromR2viaR1()
peer := peerR1() │ peer1 := peerR1()
pList, err := tm.ProcessUpdate(peer, bgpMessage) │ pList, err := tm.ProcessUpdate(peer1, bgpMessage1)
assert.Equal(t, len(pList), 1) │ assert.Equal(t, 1, len(pList))
│ assert.Equal(t, pList[0].IsWithdraw, false)
│ assert.NoError(t, err)
│ bgpMessage2 := update_fromR2()
│ peer2 := peerR2()
│ pList, err = tm.ProcessUpdate(peer2, bgpMessage2)
│ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage2.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │ expectedOrigin := pathAttributes[0]
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[1]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │ expectedNexthopAttr := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
pathNexthop := attr.(*bgp.PathAttributeNextHop) │ pathNexthop := attr.(*bgp.PathAttributeNextHop)
assert.Equal(t, expectedNexthopAttr, pathNexthop) │ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 4, len(path.GetPathAttrs())) │ assert.Equal(t, 4, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "20.20.20.0/24"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "192.168.100.1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/table/table_manager_test.go:79 │ gobgp/internal/pkg/table/table_manager_test.go:129
│
│
tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) │ tm := NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv6_UC})
│
bgpMessage := update_fromR1() │ bgpMessage := update_fromR1_ipv6()
peer := peerR1() │ peer := peerR1()
pList, err := tm.ProcessUpdate(peer, bgpMessage) │ pList, err := tm.ProcessUpdate(peer, bgpMessage)
assert.Equal(t, len(pList), 1) │ assert.Equal(t, 1, len(pList))
assert.Equal(t, pList[0].IsWithdraw, false) │ assert.Equal(t, pList[0].IsWithdraw, false)
assert.NoError(t, err) │ assert.NoError(t, err)
│
// check type │ // check type
path := pList[0] │ path := pList[0]
assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv4_UC) │ assert.Equal(t, path.GetRouteFamily(), bgp.RF_IPv6_UC)
│
// check PathAttribute │ // check PathAttribute
pathAttributes := bgpMessage.Body.(*bgp.BGPUpdate).PathAttributes │ pathAttributes := bgpMessage.Body.(*bgp.BGPUpdate).PathAttributes
expectedOrigin := pathAttributes[0] │
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) │ expectedNexthopAttr := pathAttributes[0]
│ attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
│ pathNexthop := attr.(*bgp.PathAttributeMpReachNLRI)
│ assert.Equal(t, expectedNexthopAttr, pathNexthop)
│
│ expectedOrigin := pathAttributes[1]
│ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN)
pathOrigin := attr.(*bgp.PathAttributeOrigin) │ pathOrigin := attr.(*bgp.PathAttributeOrigin)
assert.Equal(t, expectedOrigin, pathOrigin) │ assert.Equal(t, expectedOrigin, pathOrigin)
│
expectedAsPath := pathAttributes[1] │ expectedAsPath := pathAttributes[2]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
pathAspath := attr.(*bgp.PathAttributeAsPath) │ pathAspath := attr.(*bgp.PathAttributeAsPath)
assert.Equal(t, expectedAsPath, pathAspath) │ assert.Equal(t, expectedAsPath, pathAspath)
│
expectedNexthopAttr := pathAttributes[2] │
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) │
pathNexthop := attr.(*bgp.PathAttributeNextHop) │
assert.Equal(t, expectedNexthopAttr, pathNexthop) │
│
expectedMed := pathAttributes[3] │ expectedMed := pathAttributes[3]
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) │ attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
pathMed := attr.(*bgp.PathAttributeMultiExitDisc) │ pathMed := attr.(*bgp.PathAttributeMultiExitDisc)
assert.Equal(t, expectedMed, pathMed) │ assert.Equal(t, expectedMed, pathMed)
│
// check PathAttribute length │ // check PathAttribute length
assert.Equal(t, 4, len(path.GetPathAttrs())) │ assert.Equal(t, 4, len(path.GetPathAttrs()))
│
// check destination │ // check destination
expectedPrefix := "10.10.10.0/24" │ expectedPrefix := "2001:123:123:1::/64"
assert.Equal(t, expectedPrefix, path.getPrefix()) │ assert.Equal(t, expectedPrefix, path.getPrefix())
// check nexthop │ // check nexthop
expectedNexthop := "192.168.50.1" │ expectedNexthop := "2001::192:168:50:1"
assert.Equal(t, expectedNexthop, path.GetNexthop().String()) │ assert.Equal(t, expectedNexthop, path.GetNexthop().String())
│
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:1149 │ gobgp/internal/pkg/config/bgp_configs.go:1119
│
// original -> gobgp:enabled │ // original -> gobgp:enabled
// gobgp:enabled's original type is boolean. │ // gobgp:enabled's original type is boolean.
// Configure enabling to connect to zebra. │ // Configure enabling to connect to zebra.
Enabled bool `mapstructure:"enabled" json:"enabled,omitempty"` │ Enabled bool `mapstructure:"enabled" json:"enabled,omitempty"`
// original -> gobgp:url │ // original -> gobgp:url
// Configure url for zebra. │ // Configure url for zebra.
Url string `mapstructure:"url" json:"url,omitempty"` │ Url string `mapstructure:"url" json:"url,omitempty"`
// original -> gobgp:redistribute-route-type │ // original -> gobgp:redistribute-route-type
RedistributeRouteTypeList []string `mapstructure:"redistribute-route-type-list" │ RedistributeRouteTypeList []string `mapstructure:"redistribute-route-type-list"
// original -> gobgp:version │ // original -> gobgp:version
// Configure version of zebra protocol. Default is 2. │ // Configure version of zebra protocol. Default is 2.
// Supported version are 2 or 3 for Quagga and 4, 5 or 6 for FRRouting. │ // Supported version are 2 or 3 for Quagga and 4, 5 or 6 for FRRouting.
Version uint8 `mapstructure:"version" json:"version,omitempty"` │ Version uint8 `mapstructure:"version" json:"version,omitempty"`
// original -> gobgp:nexthop-trigger-enable │ // original -> gobgp:nexthop-trigger-enable
// gobgp:nexthop-trigger-enable's original type is boolean. │ // gobgp:nexthop-trigger-enable's original type is boolean.
NexthopTriggerEnable bool `mapstructure:"nexthop-trigger-enable" json:"nexthop-t │ NexthopTriggerEnable bool `mapstructure:"nexthop-trigger-enable" json:"nexthop-t
// original -> gobgp:nexthop-trigger-delay │ // original -> gobgp:nexthop-trigger-delay
NexthopTriggerDelay uint8 `mapstructure:"nexthop-trigger-delay" json:"nexthop-tr │ NexthopTriggerDelay uint8 `mapstructure:"nexthop-trigger-delay" json:"nexthop-tr
// original -> gobgp:mpls-label-range-size │ // original -> gobgp:mpls-label-range-size
// Configure MPLS label range size which will be requested to │ // Configure MPLS label range size which will be requested to
// FRR/Zebra. │ // FRR/Zebra.
MplsLabelRangeSize uint32 `mapstructure:"mpls-label-range-size" json:"mpls-label │ MplsLabelRangeSize uint32 `mapstructure:"mpls-label-range-size" json:"mpls-label
// original -> gobgp:software-name │ // original -> gobgp:software-name
// Configure zebra software name. │ // Configure zebra software name.
// frr4, cumulus, frr6, frr7, frr7.2 and frr7.3 can be used. │ // frr4, cumulus, frr6, frr7, frr7.2 and frr7.3 can be used.
SoftwareName string `mapstructure:"software-name" json:"software-name,omitempty" │ SoftwareName string `mapstructure:"software-name" json:"software-name,omitempty"
} │
next prev up gobgp/api/gobgp.pb.go:5851 │ gobgp/api/gobgp.pb.go:5724
│
state protoimpl.MessageState │ state protoimpl.MessageState
sizeCache protoimpl.SizeCache │ sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields │ unknownFields protoimpl.UnknownFields
│
ApplyPolicy *ApplyPolicy `protobuf:"bytes,1,opt,name=apply_policy,json=a │ ApplyPolicy *ApplyPolicy `protobuf:"bytes,1,opt,name=apply_policy,json=a
Conf *PeerGroupConf `protobuf:"bytes,2,opt,name=conf,proto3" json:" │ Conf *PeerConf `protobuf:"bytes,2,opt,name=conf,proto3" json:"
EbgpMultihop *EbgpMultihop `protobuf:"bytes,3,opt,name=ebgp_multihop,json= │ EbgpMultihop *EbgpMultihop `protobuf:"bytes,3,opt,name=ebgp_multihop,json=
RouteReflector *RouteReflector `protobuf:"bytes,4,opt,name=route_reflector,jso │ RouteReflector *RouteReflector `protobuf:"bytes,4,opt,name=route_reflector,jso
Info *PeerGroupState `protobuf:"bytes,5,opt,name=info,proto3" json:" │ State *PeerState `protobuf:"bytes,5,opt,name=state,proto3" json:
Timers *Timers `protobuf:"bytes,6,opt,name=timers,proto3" json │ Timers *Timers `protobuf:"bytes,6,opt,name=timers,proto3" json
Transport *Transport `protobuf:"bytes,7,opt,name=transport,proto3" j │ Transport *Transport `protobuf:"bytes,7,opt,name=transport,proto3" j
RouteServer *RouteServer `protobuf:"bytes,8,opt,name=route_server,json=r │ RouteServer *RouteServer `protobuf:"bytes,8,opt,name=route_server,json=r
GracefulRestart *GracefulRestart `protobuf:"bytes,9,opt,name=graceful_restart,js │ GracefulRestart *GracefulRestart `protobuf:"bytes,9,opt,name=graceful_restart,js
AfiSafis []*AfiSafi `protobuf:"bytes,10,rep,name=afi_safis,json=afi │ AfiSafis []*AfiSafi `protobuf:"bytes,10,rep,name=afi_safis,json=afi
TtlSecurity *TtlSecurity `protobuf:"bytes,11,opt,name=ttl_security,json= │ TtlSecurity *TtlSecurity `protobuf:"bytes,11,opt,name=ttl_security,json=
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2480 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-101" │
ma := "100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
v, err := newPath.GetMed() │
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, ma, newMed) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2480 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-101" │
ma := "100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
v, err := newPath.GetMed() │
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, ma, newMed) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2480 │ gobgp/internal/pkg/table/policy_test.go:2388
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(1)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-101" │ m := fmt.Sprintf("+%d", uint32(math.MaxUint32))
ma := "100" │ ma := "1"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2344 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "+200" │
ma := "300" │
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
pType, newPath := p.Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │
assert.NotEqual(t, nil, newPath) │
│
v, err := newPath.GetMed() │ pType, newPath := p.Apply(logger, path, nil)
assert.Nil(t, err) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
newMed := fmt.Sprintf("%d", v) │ assert.NotEqual(nil, newPath)
assert.Equal(t, ma, newMed) │ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2434 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │
ma := "50" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
v, err := newPath.GetMed() │
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, ma, newMed) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2344 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "+200" │
ma := "300" │
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
pType, newPath := p.Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │
assert.NotEqual(t, nil, newPath) │
│
v, err := newPath.GetMed() │ pType, newPath := p.Apply(logger, path, nil)
assert.Nil(t, err) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
newMed := fmt.Sprintf("%d", v) │ assert.NotEqual(nil, newPath)
assert.Equal(t, ma, newMed) │ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2434 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │
ma := "50" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
v, err := newPath.GetMed() │
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, ma, newMed) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2344 │ gobgp/internal/pkg/table/policy_test.go:2388
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(1)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "+200" │ m := fmt.Sprintf("+%d", uint32(math.MaxUint32))
ma := "300" │ ma := "1"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2434 │ gobgp/internal/pkg/table/policy_test.go:2388
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(1)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := fmt.Sprintf("+%d", uint32(math.MaxUint32))
ma := "50" │ ma := "1"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2344 │ gobgp/internal/pkg/table/policy_test.go:2480
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "+200" │ m := "-101"
ma := "300" │ ma := "100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2434 │ gobgp/internal/pkg/table/policy_test.go:2480
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := "-101"
ma := "50" │ ma := "100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2434 │ gobgp/internal/pkg/table/policy_test.go:2344
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := "+200"
ma := "50" │ ma := "300"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, ma, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/message_test.go:235 │ gobgp/internal/pkg/table/message_test.go:172
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{100000, 65000, 4000, 400000, 300000, 40001} │ as4 := []uint32{400000, 300000, 40001}
as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4) │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
param4s := []*bgp.As4PathParam{as4param1} │ as5 := []uint32{10, 20, 30}
│ as4param2 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as5)
│ param4s := []*bgp.As4PathParam{as4param1, as4param2}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 2)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:1849
│
│
// create path │ // create path
│ community1 := "65000:100"
│ community2 := "65000:200"
│ community3 := "65100:100"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ communities := bgp.NewPathAttributeCommunities([]uint32{
│ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
│ })
│ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", ".*:100")
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:1895
│
│
// create path │ // create path
│ community1 := "0:1"
│ community2 := "10:1"
│ community3 := "45686:2"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ communities := bgp.NewPathAttributeCommunities([]uint32{
│ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
│ stringToCommunityValue(community3),
│ })
│ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", "^(0|45686):[0-
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:1941
│
│
// create path │ // create path
│ community1 := "65000:100"
│ community2 := "65000:200"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ communities := bgp.NewPathAttributeCommunities([]uint32{
│ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
│ })
│ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ // action NULL is obsolate
│ s.Actions.BgpActions.SetCommunity.Options = "REPLACE"
│ s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList = nil
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ //assert.Equal(t, []uint32{}, newPath.GetCommunities())
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:1805
│
│
// create path │ // create path
│ community1 := "65000:100"
│ community2 := "65000:200"
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ communities := bgp.NewPathAttributeCommunities([]uint32{
│ stringToCommunityValue(community1),
│ stringToCommunityValue(community2),
│ })
│ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community2)}, newPath.GetCommuni
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:1761
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ communities := bgp.NewPathAttributeCommunities([]uint32{
│ stringToCommunityValue("65001:200"),
│ })
│ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med, com
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │ community := "65000:100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("REPLACE", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:2388
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(1)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │ m := fmt.Sprintf("+%d", uint32(math.MaxUint32))
│ ma := "1"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │
│ v, err := newPath.GetMed()
│ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:2480
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │ m := "-101"
│ ma := "100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │
│ v, err := newPath.GetMed()
│ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:2344
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │ m := "+200"
│ ma := "300"
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │
│ v, err := newPath.GetMed()
│ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:1720 │ gobgp/internal/pkg/table/policy_test.go:2434
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
community := "65000:100" │ m := "-50"
│ ma := "50"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit │
│ v, err := newPath.GetMed()
│ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:472 │ gobgp/internal/pkg/table/policy_test.go:633
│
// setup │ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65005}), │ bgp.NewAs4PathParam(2, []uint32{
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}), │ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ }),
│ bgp.NewAs4PathParam(1, []uint32{
│ createAs4Value("65001.1"),
│ createAs4Value("65000.1"),
│ createAs4Value("65004.1"),
│ createAs4Value("65005.1"),
│ }),
} │ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate)) │ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create match condition │ // create match condition
asPathLength := config.AsPathLength{ │ asPathLength := config.AsPathLength{
Operator: "eq", │ Operator: "eq",
Value: 5, │ Value: 5,
} │ }
c, _ := NewAsPathLengthCondition(asPathLength) │ c, _ := NewAsPathLengthCondition(asPathLength)
│
// test │ // test
assert.Equal(t, true, c.Evaluate(path, nil)) │ assert.Equal(t, true, c.Evaluate(path, nil))
│
// create match condition │ // create match condition
asPathLength = config.AsPathLength{ │ asPathLength = config.AsPathLength{
Operator: "ge", │ Operator: "ge",
Value: 3, │ Value: 3,
} │ }
c, _ = NewAsPathLengthCondition(asPathLength) │ c, _ = NewAsPathLengthCondition(asPathLength)
│
// test │ // test
assert.Equal(t, true, c.Evaluate(path, nil)) │ assert.Equal(t, true, c.Evaluate(path, nil))
│
// create match condition │ // create match condition
asPathLength = config.AsPathLength{ │ asPathLength = config.AsPathLength{
Operator: "le", │ Operator: "le",
Value: 3, │ Value: 3,
} │ }
c, _ = NewAsPathLengthCondition(asPathLength) │ c, _ = NewAsPathLengthCondition(asPathLength)
│
// test │ // test
assert.Equal(t, false, c.Evaluate(path, nil)) │ assert.Equal(t, false, c.Evaluate(path, nil))
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
v, err := newPath.GetMed() │ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, m, newMed) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
v, err := newPath.GetMed() │ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, m, newMed) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:2388
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(1)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │ m := fmt.Sprintf("+%d", uint32(math.MaxUint32))
│ ma := "1"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, m, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:2480
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │ m := "-101"
│ ma := "100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, m, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:2344
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │ m := "+200"
│ ma := "300"
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, m, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:2434
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │ m := "-50"
│ ma := "50"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
v, err := newPath.GetMed() │ v, err := newPath.GetMed()
assert.Nil(t, err) │ assert.Nil(t, err)
newMed := fmt.Sprintf("%d", v) │ newMed := fmt.Sprintf("%d", v)
assert.Equal(t, m, newMed) │ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2300 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(100) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "200" │ community := "65000:100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
v, err := newPath.GetMed() │ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
assert.Nil(t, err) │
newMed := fmt.Sprintf("%d", v) │
assert.Equal(t, m, newMed) │
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:3291 │ gobgp/internal/pkg/config/bgp_configs.go:1909
│
if lhs == nil || rhs == nil { │ if lhs == nil || rhs == nil {
return false │ return false
} │ }
if !lhs.Config.Equal(&(rhs.Config)) { │ if !lhs.Config.Equal(&(rhs.Config)) {
return false │ return false
} │ }
if !lhs.Timers.Equal(&(rhs.Timers)) { │ if !lhs.Timers.Equal(&(rhs.Timers)) {
return false │ return false
} │ }
if !lhs.Transport.Equal(&(rhs.Transport)) { │ if !lhs.Transport.Equal(&(rhs.Transport)) {
return false │ return false
} │ }
if !lhs.ErrorHandling.Equal(&(rhs.ErrorHandling)) { │ if !lhs.ErrorHandling.Equal(&(rhs.ErrorHandling)) {
return false │ return false
} │ }
if !lhs.LoggingOptions.Equal(&(rhs.LoggingOptions)) { │ if !lhs.LoggingOptions.Equal(&(rhs.LoggingOptions)) {
return false │ return false
} │ }
if !lhs.EbgpMultihop.Equal(&(rhs.EbgpMultihop)) { │ if !lhs.EbgpMultihop.Equal(&(rhs.EbgpMultihop)) {
return false │ return false
} │ }
if !lhs.RouteReflector.Equal(&(rhs.RouteReflector)) { │ if !lhs.RouteReflector.Equal(&(rhs.RouteReflector)) {
return false │ return false
} │ }
if !lhs.AsPathOptions.Equal(&(rhs.AsPathOptions)) { │ if !lhs.AsPathOptions.Equal(&(rhs.AsPathOptions)) {
return false │ return false
} │ }
if !lhs.AddPaths.Equal(&(rhs.AddPaths)) { │ if !lhs.AddPaths.Equal(&(rhs.AddPaths)) {
return false │ return false
} │ }
if len(lhs.AfiSafis) != len(rhs.AfiSafis) { │ if len(lhs.AfiSafis) != len(rhs.AfiSafis) {
return false │ return false
} │ }
{ │ {
lmap := make(map[string]*AfiSafi) │ lmap := make(map[string]*AfiSafi)
for i, l := range lhs.AfiSafis { │ for i, l := range lhs.AfiSafis {
lmap[mapkey(i, string(l.Config.AfiSafiName))] = &lhs.AfiSafis[i] │ lmap[mapkey(i, string(l.Config.AfiSafiName))] = &lhs.AfiSafis[i]
} │ }
for i, r := range rhs.AfiSafis { │ for i, r := range rhs.AfiSafis {
if l, y := lmap[mapkey(i, string(r.Config.AfiSafiName))]; !y { │ if l, y := lmap[mapkey(i, string(r.Config.AfiSafiName))]; !y {
return false │ return false
} else if !r.Equal(l) { │ } else if !r.Equal(l) {
return false │ return false
} │ }
} │ }
} │ }
if !lhs.GracefulRestart.Equal(&(rhs.GracefulRestart)) { │ if !lhs.GracefulRestart.Equal(&(rhs.GracefulRestart)) {
return false │ return false
} │ }
if !lhs.ApplyPolicy.Equal(&(rhs.ApplyPolicy)) { │ if !lhs.ApplyPolicy.Equal(&(rhs.ApplyPolicy)) {
return false │ return false
} │ }
if !lhs.UseMultiplePaths.Equal(&(rhs.UseMultiplePaths)) { │ if !lhs.UseMultiplePaths.Equal(&(rhs.UseMultiplePaths)) {
return false │ return false
} │ }
if !lhs.RouteServer.Equal(&(rhs.RouteServer)) { │ if !lhs.RouteServer.Equal(&(rhs.RouteServer)) {
return false │ return false
} │ }
if !lhs.TtlSecurity.Equal(&(rhs.TtlSecurity)) { │ if !lhs.TtlSecurity.Equal(&(rhs.TtlSecurity)) {
return false │ return false
} │ }
return true │ return true
} │
next prev up gobgp/internal/pkg/table/message_test.go:261 │ gobgp/internal/pkg/table/message_test.go:172
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{300000, 40001} │ as4 := []uint32{400000, 300000, 40001}
as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4) │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
param4s := []*bgp.As4PathParam{as4param1} │ as5 := []uint32{10, 20, 30}
│ as4param2 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as5)
│ param4s := []*bgp.As4PathParam{as4param1, as4param2}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 2)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:261 │ gobgp/internal/pkg/table/message_test.go:235
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{300000, 40001} │ as4 := []uint32{100000, 65000, 4000, 400000, 300000, 40001}
as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4) │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
param4s := []*bgp.As4PathParam{as4param1} │ param4s := []*bgp.As4PathParam{as4param1}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:309 │ gobgp/internal/pkg/table/message_test.go:172
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{} │ as4 := []uint32{400000, 300000, 40001}
as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4) │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
param4s := []*bgp.As4PathParam{as4param1} │ as5 := []uint32{10, 20, 30}
│ as4param2 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as5)
│ param4s := []*bgp.As4PathParam{as4param1, as4param2}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 2)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:309 │ gobgp/internal/pkg/table/message_test.go:235
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{} │ as4 := []uint32{100000, 65000, 4000, 400000, 300000, 40001}
as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4) │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
param4s := []*bgp.As4PathParam{as4param1} │ param4s := []*bgp.As4PathParam{as4param1}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:309 │ gobgp/internal/pkg/table/message_test.go:261
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{} │ as4 := []uint32{300000, 40001}
as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4) │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
param4s := []*bgp.As4PathParam{as4param1} │ param4s := []*bgp.As4PathParam{as4param1}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/config/bgp_configs.go:1424 │ gobgp/internal/pkg/config/bgp_configs.go:1395
│
// original -> gobgp:address │ // original -> gobgp:address
// gobgp:address's original type is inet:ip-address. │ // gobgp:address's original type is inet:ip-address.
// Reference to the address of the BMP server used as │ // Reference to the address of the BMP server used as
// a key in the BMP server list. │ // a key in the BMP server list.
Address string `mapstructure:"address" json:"address,omitempty"` │ Address string `mapstructure:"address" json:"address,omitempty"`
// original -> gobgp:port │ // original -> gobgp:port
// Reference to the port of the BMP server. │ // Reference to the port of the BMP server.
Port uint32 `mapstructure:"port" json:"port,omitempty"` │ Port uint32 `mapstructure:"port" json:"port,omitempty"`
// original -> gobgp:route-monitoring-policy │ // original -> gobgp:route-monitoring-policy
RouteMonitoringPolicy BmpRouteMonitoringPolicyType `mapstructure:"route-monitori │ RouteMonitoringPolicy BmpRouteMonitoringPolicyType `mapstructure:"route-monitori
// original -> gobgp:statistics-timeout │ // original -> gobgp:statistics-timeout
// Interval seconds of statistics messages sent to BMP server. │ // Interval seconds of statistics messages sent to BMP server.
StatisticsTimeout uint16 `mapstructure:"statistics-timeout" json:"statistics-tim │ StatisticsTimeout uint16 `mapstructure:"statistics-timeout" json:"statistics-tim
// original -> gobgp:route-mirroring-enabled │ // original -> gobgp:route-mirroring-enabled
// gobgp:route-mirroring-enabled's original type is boolean. │ // gobgp:route-mirroring-enabled's original type is boolean.
// Enable feature for mirroring of received BGP messages │ // Enable feature for mirroring of received BGP messages
// mainly for debugging purpose. │ // mainly for debugging purpose.
RouteMirroringEnabled bool `mapstructure:"route-mirroring-enabled" json:"route-m │ RouteMirroringEnabled bool `mapstructure:"route-mirroring-enabled" json:"route-m
// original -> gobgp:sys-name │ // original -> gobgp:sys-name
// Reference to the SysName of the BMP server. │ // Reference to the SysName of the BMP server.
SysName string `mapstructure:"sys-name" json:"sys-name,omitempty"` │ SysName string `mapstructure:"sys-name" json:"sys-name,omitempty"`
// original -> gobgp:sys-descr │ // original -> gobgp:sys-descr
// Reference to the SysDescr of the BMP server. │ // Reference to the SysDescr of the BMP server.
SysDescr string `mapstructure:"sys-descr" json:"sys-descr,omitempty"` │ SysDescr string `mapstructure:"sys-descr" json:"sys-descr,omitempty"`
} │
next prev up gobgp/internal/pkg/table/message_test.go:81 │ gobgp/internal/pkg/table/message_test.go:172
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{400000, 300000, 40001} │ as4 := []uint32{400000, 300000, 40001}
param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ as5 := []uint32{10, 20, 30}
│ as4param2 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as5)
│ param4s := []*bgp.As4PathParam{as4param1, as4param2}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 2)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
│ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[1].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:81 │ gobgp/internal/pkg/table/message_test.go:235
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{400000, 300000, 40001} │ as4 := []uint32{100000, 65000, 4000, 400000, 300000, 40001}
param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:81 │ gobgp/internal/pkg/table/message_test.go:261
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{400000, 300000, 40001} │ as4 := []uint32{300000, 40001}
param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:81 │ gobgp/internal/pkg/table/message_test.go:309
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
as4 := []uint32{400000, 300000, 40001} │ as4 := []uint32{}
param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, │ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
as4path := bgp.NewPathAttributeAs4Path(param4s) │ as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/api/gobgp.pb.go:6318 │ gobgp/api/gobgp.pb.go:6429
│
state protoimpl.MessageState │ state protoimpl.MessageState
sizeCache protoimpl.SizeCache │ sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields │ unknownFields protoimpl.UnknownFields
│
AuthPassword string `protobuf:"bytes,1,opt,name=auth_password,json=au │ AuthPassword string `protobuf:"bytes,1,opt,name=auth_password,json=au
Description string `protobuf:"bytes,2,opt,name=description,proto3" j │ Description string `protobuf:"bytes,2,opt,name=description,proto3" j
LocalAsn uint32 `protobuf:"varint,3,opt,name=local_asn,json=local │ LocalAsn uint32 `protobuf:"varint,3,opt,name=local_asn,json=local
PeerAsn uint32 `protobuf:"varint,4,opt,name=peer_asn,json=peerAs │ PeerAsn uint32 `protobuf:"varint,4,opt,name=peer_asn,json=peerAs
PeerGroupName string `protobuf:"bytes,5,opt,name=peer_group_name,json= │ PeerGroupName string `protobuf:"bytes,5,opt,name=peer_group_name,json=
Type PeerType `protobuf:"varint,6,opt,name=type,proto3,enum=api │ Type PeerType `protobuf:"varint,6,opt,name=type,proto3,enum=api
RemovePrivate RemovePrivate `protobuf:"varint,7,opt,name=remove_private,json= │ RemovePrivate RemovePrivate `protobuf:"varint,7,opt,name=remove_private,json=
RouteFlapDamping bool `protobuf:"varint,8,opt,name=route_flap_damping,j │ RouteFlapDamping bool `protobuf:"varint,8,opt,name=route_flap_damping,j
SendCommunity uint32 `protobuf:"varint,9,opt,name=send_community,json= │ SendCommunity uint32 `protobuf:"varint,9,opt,name=send_community,json=
│ TotalPaths uint32 `protobuf:"varint,10,opt,name=total_paths,json=to
│ TotalPrefixes uint32 `protobuf:"varint,11,opt,name=total_prefixes,json
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
_, err = newPath.GetMed() │
assert.NotNil(t, err) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:2388
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(1)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := fmt.Sprintf("+%d", uint32(math.MaxUint32))
│ ma := "1"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
_, err = newPath.GetMed() │ v, err := newPath.GetMed()
assert.NotNil(t, err) │ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:2480
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := "-101"
│ ma := "100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
_, err = newPath.GetMed() │ v, err := newPath.GetMed()
assert.NotNil(t, err) │ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:2344
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := "+200"
│ ma := "300"
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
_, err = newPath.GetMed() │ v, err := newPath.GetMed()
assert.NotNil(t, err) │ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:2434
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := "-50"
│ ma := "50"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│
_, err = newPath.GetMed() │ v, err := newPath.GetMed()
assert.NotNil(t, err) │ assert.Nil(t, err)
│ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, ma, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ community := "65000:100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
_, err = newPath.GetMed() │
assert.NotNil(t, err) │
} │
next prev up gobgp/internal/pkg/table/policy_test.go:2526 │ gobgp/internal/pkg/table/policy_test.go:2300
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
│ med := bgp.NewPathAttributeMultiExitDisc(100)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
m := "-50" │ m := "200"
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) │ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
p := r.policyMap["pd1"] │ p := r.policyMap["pd1"]
│
pType, newPath := p.Apply(logger, path, nil) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath) │ assert.NotEqual(t, nil, newPath)
│ v, err := newPath.GetMed()
_, err = newPath.GetMed() │ assert.Nil(t, err)
assert.NotNil(t, err) │ newMed := fmt.Sprintf("%d", v)
│ assert.Equal(t, m, newMed)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:521 │ gobgp/internal/pkg/table/policy_test.go:585
│
│ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
│ bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", true) │
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"} │ // create match condition
│ asPathLength := config.AsPathLength{
│ Operator: "le",
│ Value: 10,
│ }
│
│ s := createStatement("statement1", "ps1", "ns1", false)
│ s.Conditions.BgpConditions.AsPathLength = asPathLength
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ pType, newPath := p.Apply(logger, path, nil)
│ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
│
} │
next prev up gobgp/internal/pkg/table/policy_test.go:521 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"} │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
} │
next prev up gobgp/internal/pkg/table/policy_test.go:521 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"} │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:521 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
│ community := "65000:100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"} │ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
│
│ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, newPath, path) │ assert.NotEqual(t, nil, newPath)
│ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:649 │ gobgp/pkg/apiutil/attribute_test.go:509
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
esi := &api.EthernetSegmentIdentifier{ │ esi := &api.EthernetSegmentIdentifier{
Type: 0, │ Type: 0,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
} │ }
a, err := apb.New(&api.EVPNIPPrefixRoute{ │ a, err := apb.New(&api.EVPNMACIPAdvertisementRoute{
Rd: rd, │ Rd: rd,
Esi: esi, │ Esi: esi,
EthernetTag: 100, │ EthernetTag: 100,
IpPrefixLen: 24, │ MacAddress: "aa:bb:cc:dd:ee:ff",
IpPrefix: "192.168.101.0", │ IpAddress: "192.168.101.1",
Label: 200, │ Labels: []uint32{200},
GwAddress: "172.16.101.1", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/policy_test.go:553 │ gobgp/internal/pkg/table/policy_test.go:585
│
│ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
│ bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", true) │
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"} │ // create match condition
│ asPathLength := config.AsPathLength{
│ Operator: "le",
│ Value: 10,
│ }
│
│ s := createStatement("statement1", "ps1", "ns1", false)
│ s.Conditions.BgpConditions.AsPathLength = asPathLength
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ pType, newPath := p.Apply(logger, path, nil)
│ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
│
} │
next prev up gobgp/internal/pkg/table/policy_test.go:553 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"} │ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
} │
next prev up gobgp/internal/pkg/table/policy_test.go:553 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"} │ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:553 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
│ community := "65000:100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"} │ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
assert.Equal(t, ROUTE_TYPE_NONE, pType) │
assert.Equal(t, newPath, path) │ pType, newPath := p.Apply(logger, path, nil)
│ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(t, nil, newPath)
│ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
} │
next prev up gobgp/internal/pkg/table/policy_test.go:553 │ gobgp/internal/pkg/table/policy_test.go:521
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"} │ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2958 │ gobgp/pkg/packet/bgp/bgp_test.go:2975
[]byte{ │ []byte{
0x00, 0x02, 0x00, 0x69, // Link NLRI, correct length │ 0x00, 0x02, 0x00, 0x81, // Link NLRI, correct length
0x02, // Protocol ISIS │ 0x02, // Protocol ISIS
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID │ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID
0x01, 0x00, 0x00, 0x22, // Local Node Desc │ 0x01, 0x00, 0x00, 0x22, // Local Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T │ 0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T
0x01, 0x01, 0x00, 0x22, // Remote Node Desc │ 0x01, 0x01, 0x00, 0x22, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T │ 0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T
0x01, 0x03, 0x00, 0x04, 0x01, 0x01, 0x01, 0x01, // IPv4 Interfac │ 0x01, 0x05, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
0x01, 0x04, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, // IPv4 Neighbor │ 0x01, 0x06, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
}, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.0201 │ }, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.020
next prev up gobgp/pkg/packet/bgp/bgp_test.go:1521 │ gobgp/pkg/packet/bgp/bgp_test.go:1484
│
assert := assert.New(t) │ assert := assert.New(t)
│
var tests = []struct { │ var tests = []struct {
in []byte │ in []byte
want string │ want string
serialize bool │ serialize bool
err bool │ err bool
}{ │ }{
{[]byte{0x01, 0x06, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00 │ {[]byte{0x01, 0x05, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
{[]byte{0x01, 0x06, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00 │ {[]byte{0x01, 0x05, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
{[]byte{0x01, 0x06, 0x00, 0x10, 0xfe, 0x81, 0x0d, 0xb8, 0x00, 0x00, 0x00 │ {[]byte{0x01, 0x05, 0x00, 0x10, 0xfe, 0x80, 0x0d, 0xb8, 0x00, 0x00, 0x00
{[]byte{0x01, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00}, "", false, true}, │ {[]byte{0x01, 0x05, 0x00, 0x03, 0x00, 0x00, 0x00}, "", false, true},
{[]byte{0xfe, 0xfe, 0x00, 0x00}, "", false, true}, │ {[]byte{0xfe, 0xfe, 0x00, 0x00}, "", false, true},
} │ }
│
for _, test := range tests { │ for _, test := range tests {
tlv := LsTLVIPv6NeighborAddr{} │ tlv := LsTLVIPv6InterfaceAddr{}
if test.err { │ if test.err {
assert.Error(tlv.DecodeFromBytes(test.in)) │ assert.Error(tlv.DecodeFromBytes(test.in))
continue │ continue
} else { │ } else {
assert.NoError(tlv.DecodeFromBytes(test.in)) │ assert.NoError(tlv.DecodeFromBytes(test.in))
} │ }
│
got, err := tlv.MarshalJSON() │ got, err := tlv.MarshalJSON()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(got, []byte(test.want)) │ assert.Equal(got, []byte(test.want))
│
if test.serialize { │ if test.serialize {
s, err := tlv.Serialize() │ s, err := tlv.Serialize()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(test.in, s) │ assert.Equal(test.in, s)
} │ }
} │ }
} │
next prev up gobgp/api/gobgp.pb.go:8059 │ gobgp/api/gobgp.pb.go:7964
│
state protoimpl.MessageState │ state protoimpl.MessageState
sizeCache protoimpl.SizeCache │ sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields │ unknownFields protoimpl.UnknownFields
│
AlwaysCompareMed bool `protobuf:"varint,1,opt,name=always_compare_med,js │ AlwaysCompareMed bool `protobuf:"varint,1,opt,name=always_compare_med,js
IgnoreAsPathLength bool `protobuf:"varint,2,opt,name=ignore_as_path_length │ IgnoreAsPathLength bool `protobuf:"varint,2,opt,name=ignore_as_path_length
ExternalCompareRouterId bool `protobuf:"varint,3,opt,name=external_compare_rout │ ExternalCompareRouterId bool `protobuf:"varint,3,opt,name=external_compare_rout
AdvertiseInactiveRoutes bool `protobuf:"varint,4,opt,name=advertise_inactive_ro │ AdvertiseInactiveRoutes bool `protobuf:"varint,4,opt,name=advertise_inactive_ro
EnableAigp bool `protobuf:"varint,5,opt,name=enable_aigp,json=enab │ EnableAigp bool `protobuf:"varint,5,opt,name=enable_aigp,json=enab
IgnoreNextHopIgpMetric bool `protobuf:"varint,6,opt,name=ignore_next_hop_igp_m │ IgnoreNextHopIgpMetric bool `protobuf:"varint,6,opt,name=ignore_next_hop_igp_m
DisableBestPathSelection bool `protobuf:"varint,7,opt,name=disable_best_path_sel │ DisableBestPathSelection bool `protobuf:"varint,7,opt,name=disable_best_path_sel
} │
next prev up gobgp/internal/pkg/table/policy_test.go:293 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, path, newPath) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
} │
next prev up gobgp/internal/pkg/table/policy_test.go:293 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, path, newPath) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:293 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
│ community := "65000:100"
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
│
│ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, path, newPath) │ assert.NotEqual(t, nil, newPath)
│ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
} │
next prev up gobgp/internal/pkg/table/policy_test.go:293 │ gobgp/internal/pkg/table/policy_test.go:521
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, path, newPath) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:293 │ gobgp/internal/pkg/table/policy_test.go:553
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", true) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
//test │
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType) │ assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Equal(t, path, newPath) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:262 │ gobgp/internal/pkg/table/policy_test.go:585
│
│ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
│ bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
│ // create match condition
│ asPathLength := config.AsPathLength{
│ Operator: "le",
│ Value: 10,
│ }
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", false)
│ s.Conditions.BgpConditions.AsPathLength = asPathLength
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
│ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
│
} │
next prev up gobgp/internal/pkg/table/policy_test.go:262 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:262 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", false) │ community := "65000:100"
│
│ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │
assert.Equal(t, newPath, path) │ pType, newPath := p.Apply(logger, path, nil)
│ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(t, nil, newPath)
│ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
} │
next prev up gobgp/internal/pkg/table/policy_test.go:262 │ gobgp/internal/pkg/table/policy_test.go:521
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│ s := createStatement("statement1", "ps1", "ns1", true)
s := createStatement("statement1", "ps1", "ns1", false) │ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:262 │ gobgp/internal/pkg/table/policy_test.go:553
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│ s := createStatement("statement1", "ps1", "ns1", true)
s := createStatement("statement1", "ps1", "ns1", false) │ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:262 │ gobgp/internal/pkg/table/policy_test.go:293
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", true)
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_REJECT, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, path, newPath)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:585
│
│ // setup
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
│ bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
│ }
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│ UpdatePathAttrs4ByteAs(logger, updateMsg.Body.(*bgp.BGPUpdate))
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
│ // create match condition
│ asPathLength := config.AsPathLength{
│ Operator: "le",
│ Value: 10,
│ }
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", false)
│ s.Conditions.BgpConditions.AsPathLength = asPathLength
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ pType, newPath := p.Apply(logger, path, nil)
│ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
│
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:2567
│
│
│ assert := assert.New(t)
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", false) │
│ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:2612
│
│
│ assert := assert.New(t)
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65002,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
│
│ body := updateMsg.Body.(*bgp.BGPUpdate)
│ UpdatePathAttrs4ByteAs(logger, body)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", false) │
│ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
│ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ r.reload(pl)
assert.Nil(t, err) │ p := r.policyMap["pd1"]
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ pType, newPath := p.Apply(logger, path, nil)
assert.Equal(t, newPath, path) │ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(nil, newPath)
│ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, n
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:1720
│
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
│
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", false) │
│ community := "65000:100"
│
│ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
│
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ p := r.policyMap["pd1"]
assert.Equal(t, ROUTE_TYPE_NONE, pType) │
assert.Equal(t, newPath, path) │ pType, newPath := p.Apply(logger, path, nil)
│ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
│ assert.NotEqual(t, nil, newPath)
│ assert.Equal(t, []uint32{stringToCommunityValue(community)}, newPath.GetCommunit
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:521
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:553
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", true)
│ s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"}
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:293
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
s := createStatement("statement1", "ps1", "ns1", false) │
│ s := createStatement("statement1", "ps1", "ns1", true)
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
│ //test
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, path, newPath)
} │
next prev up gobgp/internal/pkg/table/policy_test.go:231 │ gobgp/internal/pkg/table/policy_test.go:262
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
│
// create policy │ // create policy
ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") │ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
ns := createNeighborSet("ns1", "10.0.0.1") │ ns := createNeighborSet("ns1", "10.0.0.1")
ds := config.DefinedSets{} │ ds := config.DefinedSets{}
ds.PrefixSets = []config.PrefixSet{ps} │ ds.PrefixSets = []config.PrefixSet{ps}
ds.NeighborSets = []config.NeighborSet{ns} │ ds.NeighborSets = []config.NeighborSet{ns}
│
s := createStatement("statement1", "ps1", "ns1", false) │ s := createStatement("statement1", "ps1", "ns1", false)
pd := createPolicyDefinition("pd1", s) │ pd := createPolicyDefinition("pd1", s)
pl := createRoutingPolicy(ds, pd) │ pl := createRoutingPolicy(ds, pd)
│
r := NewRoutingPolicy(logger) │ r := NewRoutingPolicy(logger)
err := r.reload(pl) │ err := r.reload(pl)
assert.Nil(t, err) │ assert.Nil(t, err)
pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil) │ pType, newPath := r.policyMap["pd1"].Apply(logger, path, nil)
assert.Equal(t, ROUTE_TYPE_NONE, pType) │ assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Equal(t, newPath, path) │ assert.Equal(t, newPath, path)
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:461 │ gobgp/pkg/apiutil/attribute_test.go:509
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherTwoOctetASN{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: 65000, │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
esi := &api.EthernetSegmentIdentifier{ │ esi := &api.EthernetSegmentIdentifier{
Type: 0, │ Type: 0,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
} │ }
a, err := apb.New(&api.EVPNEthernetAutoDiscoveryRoute{ │ a, err := apb.New(&api.EVPNMACIPAdvertisementRoute{
Rd: rd, │ Rd: rd,
Esi: esi, │ Esi: esi,
EthernetTag: 100, │ EthernetTag: 100,
Label: 200, │ MacAddress: "aa:bb:cc:dd:ee:ff",
│ IpAddress: "192.168.101.1",
│ Labels: []uint32{200},
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:461 │ gobgp/pkg/apiutil/attribute_test.go:649
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherTwoOctetASN{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: 65000, │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
esi := &api.EthernetSegmentIdentifier{ │ esi := &api.EthernetSegmentIdentifier{
Type: 0, │ Type: 0,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
} │ }
a, err := apb.New(&api.EVPNEthernetAutoDiscoveryRoute{ │ a, err := apb.New(&api.EVPNIPPrefixRoute{
Rd: rd, │ Rd: rd,
Esi: esi, │ Esi: esi,
EthernetTag: 100, │ EthernetTag: 100,
│ IpPrefixLen: 24,
│ IpPrefix: "192.168.101.0",
Label: 200, │ Label: 200,
│ GwAddress: "172.16.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/message_test.go:287 │ gobgp/internal/pkg/table/message_test.go:235
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │ as4 := []uint32{100000, 65000, 4000, 400000, 300000, 40001}
│ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:287 │ gobgp/internal/pkg/table/message_test.go:261
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │ as4 := []uint32{300000, 40001}
│ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:287 │ gobgp/internal/pkg/table/message_test.go:309
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │ as4 := []uint32{}
│ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:287 │ gobgp/internal/pkg/table/message_test.go:81
│
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │ as4 := []uint32{400000, 300000, 40001}
│ param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ,
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
UpdatePathAttrs4ByteAs(logger, msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:602 │ gobgp/pkg/apiutil/attribute_test.go:509
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
esi := &api.EthernetSegmentIdentifier{ │ esi := &api.EthernetSegmentIdentifier{
Type: 0, │ Type: 0,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
} │ }
a, err := apb.New(&api.EVPNEthernetSegmentRoute{ │ a, err := apb.New(&api.EVPNMACIPAdvertisementRoute{
Rd: rd, │ Rd: rd,
Esi: esi, │ Esi: esi,
IpAddress: "192.168.101.1", │ EthernetTag: 100,
│ MacAddress: "aa:bb:cc:dd:ee:ff",
│ IpAddress: "192.168.101.1",
│ Labels: []uint32{200},
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:602 │ gobgp/pkg/apiutil/attribute_test.go:649
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
esi := &api.EthernetSegmentIdentifier{ │ esi := &api.EthernetSegmentIdentifier{
Type: 0, │ Type: 0,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
} │ }
a, err := apb.New(&api.EVPNEthernetSegmentRoute{ │ a, err := apb.New(&api.EVPNIPPrefixRoute{
Rd: rd, │ Rd: rd,
Esi: esi, │ Esi: esi,
IpAddress: "192.168.101.1", │ EthernetTag: 100,
│ IpPrefixLen: 24,
│ IpPrefix: "192.168.101.0",
│ Label: 200,
│ GwAddress: "172.16.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:602 │ gobgp/pkg/apiutil/attribute_test.go:461
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherTwoOctetASN{
Admin: "1.1.1.1", │ Admin: 65000,
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
esi := &api.EthernetSegmentIdentifier{ │ esi := &api.EthernetSegmentIdentifier{
Type: 0, │ Type: 0,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
} │ }
a, err := apb.New(&api.EVPNEthernetSegmentRoute{ │ a, err := apb.New(&api.EVPNEthernetAutoDiscoveryRoute{
Rd: rd, │ Rd: rd,
Esi: esi, │ Esi: esi,
IpAddress: "192.168.101.1", │ EthernetTag: 100,
│ Label: 200,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2942 │ gobgp/pkg/packet/bgp/bgp_test.go:2975
[]byte{ │ []byte{
0x00, 0x02, 0x00, 0x65, // Link NLRI, correct length │ 0x00, 0x02, 0x00, 0x81, // Link NLRI, correct length
0x02, // Protocol ISIS │ 0x02, // Protocol ISIS
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID │ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID
0x01, 0x00, 0x00, 0x22, // Local Node Desc │ 0x01, 0x00, 0x00, 0x22, // Local Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T │ 0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T
0x01, 0x01, 0x00, 0x22, // Remote Node Desc │ 0x01, 0x01, 0x00, 0x22, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T │ 0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T
0x01, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 │ 0x01, 0x05, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
│ }, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.020
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2942 │ gobgp/pkg/packet/bgp/bgp_test.go:2958
[]byte{ │ []byte{
0x00, 0x02, 0x00, 0x65, // Link NLRI, correct length │ 0x00, 0x02, 0x00, 0x69, // Link NLRI, correct length
0x02, // Protocol ISIS │ 0x02, // Protocol ISIS
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID │ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID
0x01, 0x00, 0x00, 0x22, // Local Node Desc │ 0x01, 0x00, 0x00, 0x22, // Local Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T │ 0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T
0x01, 0x01, 0x00, 0x22, // Remote Node Desc │ 0x01, 0x01, 0x00, 0x22, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T │ 0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T
0x01, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 │ 0x01, 0x03, 0x00, 0x04, 0x01, 0x01, 0x01, 0x01, // IPv4 Interfac
│ }, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.020
next prev up gobgp/pkg/apiutil/attribute_test.go:334 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.LabeledIPAddressPrefix{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Labels: []uint32{100}, │ Labels: []uint32{100},
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:1::", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.LabeledIPAddressPrefix{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Labels: []uint32{200}, │ Labels: []uint32{200},
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:2::", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_LABEL, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/message_test.go:60 │ gobgp/internal/pkg/table/message_test.go:235
│
as := []uint32{65000, 4000, 40000, 30000, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYP │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │
UpdatePathAttrs2ByteAs(msg) │ as4 := []uint32{100000, 65000, 4000, 400000, 300000, 40001}
│ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
│ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:60 │ gobgp/internal/pkg/table/message_test.go:261
│
as := []uint32{65000, 4000, 40000, 30000, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYP │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │
UpdatePathAttrs2ByteAs(msg) │ as4 := []uint32{300000, 40001}
│ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
│ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:60 │ gobgp/internal/pkg/table/message_test.go:309
│
as := []uint32{65000, 4000, 40000, 30000, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYP │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │
UpdatePathAttrs2ByteAs(msg) │ as4 := []uint32{}
│ as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)
│ param4s := []*bgp.As4PathParam{as4param1}
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
│ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:60 │ gobgp/internal/pkg/table/message_test.go:81
│
as := []uint32{65000, 4000, 40000, 30000, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYP │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │
UpdatePathAttrs2ByteAs(msg) │ as4 := []uint32{400000, 300000, 40001}
│ param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ,
│ as4path := bgp.NewPathAttributeAs4Path(param4s)
│ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path
│ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/message_test.go:60 │ gobgp/internal/pkg/table/message_test.go:287
│
as := []uint32{65000, 4000, 40000, 30000, 40001} │ as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYP │ params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE
aspath := bgp.NewPathAttributeAsPath(params) │ aspath := bgp.NewPathAttributeAsPath(params)
│
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B │ msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).B
UpdatePathAttrs2ByteAs(msg) │ UpdatePathAttrs4ByteAs(logger, msg)
assert.Equal(t, len(msg.PathAttributes), 1) │ assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1) │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(* │ assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp. │ assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.
} │
next prev up gobgp/internal/pkg/table/policy_test.go:141 │ gobgp/internal/pkg/table/policy_test.go:207
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
mpnlri := []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::" │ mpnlri := []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(64, "2001:123:123:1::"
mpreach := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlri) │ mpreach := bgp.NewPathAttributeMpReachNLRI("2001::192:168:50:1", mpnlri)
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{mpreach, origin, aspath, med} │ pathAttributes := []bgp.PathAttributeInterface{mpreach, origin, aspath, med}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// test │ // test
pl1, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange │ pl1, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange
match1 := pl1.Match(path) │ match1 := pl1.Match(path)
assert.Equal(t, false, match1) │ assert.Equal(t, false, match1)
pl2, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123:1::/64", MasklengthRan │ pl2, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange
match2 := pl2.Match(path) │ match2 := pl2.Match(path)
assert.Equal(t, true, match2) │ assert.Equal(t, false, match2)
pl3, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange │ pl3, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange
match3 := pl3.Match(path) │ match3 := pl3.Match(path)
assert.Equal(t, true, match3) │ assert.Equal(t, true, match3)
} │
next prev up gobgp/internal/pkg/table/path_test.go:97 │ gobgp/internal/pkg/table/path_test.go:204
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
│
│ asns := make([]uint16, 255)
│ for i := range asns {
│ asns[i] = 65000 + uint16(i)
│ }
│
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│
p.PrependAsn(65000, 1, false) │ expected := []uint32{65000, 65000}
assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005, 0, 0, 0}, p.GetA │ for _, v := range asns {
│ expected = append(expected, uint32(v))
│ }
│ p.PrependAsn(65000, 2, false)
│ assert.Equal(append(expected, []uint32{0, 0, 0}...), p.GetAsSeqList())
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:788 │ gobgp/pkg/apiutil/attribute_test.go:602
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rt, err := apb.New(&api.IPv4AddressSpecificExtended{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
IsTransitive: true, │ Admin: "1.1.1.1",
SubType: 0x02, // Route Target │ Assigned: 100,
Address: "1.1.1.1", │
LocalAdmin: 100, │
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.RouteTargetMembershipNLRI{ │ esi := &api.EthernetSegmentIdentifier{
Asn: 65000, │ Type: 0,
Rt: rt, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNEthernetSegmentRoute{
│ Rd: rd,
│ Esi: esi,
│ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2605 │ gobgp/pkg/packet/bgp/bgp_test.go:2568
│
assert := assert.New(t) │ assert := assert.New(t)
│
var tests = []struct { │ var tests = []struct {
in []byte │ in []byte
want string │ want string
serialize bool │ serialize bool
err bool │ err bool
}{ │ }{
{[]byte{0x04, 0x89, 0x00, 0x03, 0x01, 0x88, 0x94}, `{"type":1161,"sid_la │ {[]byte{0x04, 0x4b, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x88, 0x94
{[]byte{0x04, 0x89, 0x00, 0x03, 0x0f, 0xff, 0xff}, `{"type":1161,"sid_la │ {[]byte{0x04, 0x4b, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff
{[]byte{0x04, 0x89, 0x00, 0x03, 0xff, 0xff, 0xff}, `{"type":1161,"sid_la │ {[]byte{0x04, 0x4b, 0x00, 0x08, 0x01, 0x01, 0x00, 0x00, 0x04, 0x3B, 0x73
{[]byte{0x04, 0x89, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49}, `{"type":1161," │ {[]byte{0x04, 0x4b, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11}, "",
{[]byte{0x04, 0x89, 0x00, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05}, "", false │ {[]byte{0xfe, 0xfe, 0x00, 0x07, 0x04, 0x3B, 0x73, 0x49, 0x05, 0x06, 0x07
{[]byte{0xfe, 0xfe, 0x00, 0x04, 0x04, 0x3B, 0x73, 0x49}, "", false, true │
} │ }
│
for _, test := range tests { │ for _, test := range tests {
tlv := LsTLVSIDLabel{} │ tlv := LsTLVAdjacencySID{}
if test.err { │ if test.err {
assert.Error(tlv.DecodeFromBytes(test.in)) │ assert.Error(tlv.DecodeFromBytes(test.in))
continue │ continue
} else { │ } else {
assert.NoError(tlv.DecodeFromBytes(test.in)) │ assert.NoError(tlv.DecodeFromBytes(test.in))
} │ }
│
got, err := tlv.MarshalJSON() │ got, err := tlv.MarshalJSON()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(got, []byte(test.want)) │ assert.Equal(got, []byte(test.want))
│
if test.serialize { │ if test.serialize {
s, err := tlv.Serialize() │ s, err := tlv.Serialize()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(test.in, s) │ assert.Equal(test.in, s)
} │ }
} │ }
} │
next prev up gobgp/internal/pkg/table/path_test.go:69 │ gobgp/internal/pkg/table/path_test.go:204
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
│
│ asns := make([]uint16, 255)
│ for i := range asns {
│ asns[i] = 65000 + uint16(i)
│ }
│
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
med, │
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
assert.Equal(10, p.GetAsPathLen()) │
│ expected := []uint32{65000, 65000}
│ for _, v := range asns {
│ expected = append(expected, uint32(v))
│ }
│ p.PrependAsn(65000, 2, false)
│ assert.Equal(append(expected, []uint32{0, 0, 0}...), p.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/path_test.go:69 │ gobgp/internal/pkg/table/path_test.go:97
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
med, │
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
assert.Equal(10, p.GetAsPathLen()) │
│ p.PrependAsn(65000, 1, false)
│ assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005, 0, 0, 0}, p.GetA
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:700 │ gobgp/pkg/apiutil/attribute_test.go:509
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
Rd: rd, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
PrefixLen: 24, │ }
Prefix: "192.168.101.0", │ a, err := apb.New(&api.EVPNMACIPAdvertisementRoute{
│ Rd: rd,
│ Esi: esi,
│ EthernetTag: 100,
│ MacAddress: "aa:bb:cc:dd:ee:ff",
│ IpAddress: "192.168.101.1",
│ Labels: []uint32{200},
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:509
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
Rd: rd, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
PrefixLen: 64, │ }
Prefix: "2001:db8:1::", │ a, err := apb.New(&api.EVPNMACIPAdvertisementRoute{
│ Rd: rd,
│ Esi: esi,
│ EthernetTag: 100,
│ MacAddress: "aa:bb:cc:dd:ee:ff",
│ IpAddress: "192.168.101.1",
│ Labels: []uint32{200},
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:700 │ gobgp/pkg/apiutil/attribute_test.go:649
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
Rd: rd, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
PrefixLen: 24, │ }
Prefix: "192.168.101.0", │ a, err := apb.New(&api.EVPNIPPrefixRoute{
│ Rd: rd,
│ Esi: esi,
│ EthernetTag: 100,
│ IpPrefixLen: 24,
│ IpPrefix: "192.168.101.0",
│ Label: 200,
│ GwAddress: "172.16.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:649
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
Rd: rd, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
PrefixLen: 64, │ }
Prefix: "2001:db8:1::", │ a, err := apb.New(&api.EVPNIPPrefixRoute{
│ Rd: rd,
│ Esi: esi,
│ EthernetTag: 100,
│ IpPrefixLen: 24,
│ IpPrefix: "192.168.101.0",
│ Label: 200,
│ GwAddress: "172.16.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:461
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherTwoOctetASN{
Admin: "1.1.1.1", │ Admin: 65000,
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
Rd: rd, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
PrefixLen: 64, │ }
Prefix: "2001:db8:1::", │ a, err := apb.New(&api.EVPNEthernetAutoDiscoveryRoute{
│ Rd: rd,
│ Esi: esi,
│ EthernetTag: 100,
│ Label: 200,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:700 │ gobgp/pkg/apiutil/attribute_test.go:602
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
│ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNEthernetSegmentRoute{
Rd: rd, │ Rd: rd,
PrefixLen: 24, │ Esi: esi,
Prefix: "192.168.101.0", │ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:602
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ esi := &api.EthernetSegmentIdentifier{
Labels: []uint32{100, 200}, │ Type: 0,
│ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNEthernetSegmentRoute{
Rd: rd, │ Rd: rd,
PrefixLen: 64, │ Esi: esi,
Prefix: "2001:db8:1::", │ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:700 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 2)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Admin: "1.1.1.1", │ Labels: []uint32{100},
Assigned: 100, │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ nlris = append(nlris, a)
Labels: []uint32{100, 200}, │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Rd: rd, │ Labels: []uint32{200},
PrefixLen: 24, │ PrefixLen: 24,
Prefix: "192.168.101.0", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 2)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Admin: "1.1.1.1", │ Labels: []uint32{100},
Assigned: 100, │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ nlris = append(nlris, a)
Labels: []uint32{100, 200}, │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Rd: rd, │ Labels: []uint32{200},
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:1::", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:700 │ gobgp/pkg/apiutil/attribute_test.go:334
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 2)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Admin: "1.1.1.1", │ Labels: []uint32{100},
Assigned: 100, │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ nlris = append(nlris, a)
Labels: []uint32{100, 200}, │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Rd: rd, │ Labels: []uint32{200},
PrefixLen: 24, │ PrefixLen: 64,
Prefix: "192.168.101.0", │ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:334
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 2)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Admin: "1.1.1.1", │ Labels: []uint32{100},
Assigned: 100, │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ nlris = append(nlris, a)
Labels: []uint32{100, 200}, │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Rd: rd, │ Labels: []uint32{200},
PrefixLen: 64, │ PrefixLen: 64,
Prefix: "2001:db8:1::", │ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2643 │ gobgp/pkg/packet/bgp/bgp_test.go:2568
│
assert := assert.New(t) │ assert := assert.New(t)
│
var tests = []struct { │ var tests = []struct {
in []byte │ in []byte
want string │ want string
serialize bool │ serialize bool
err bool │ err bool
}{ │ }{
{[]byte{0x04, 0x86, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x88, 0x94 │ {[]byte{0x04, 0x4b, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x88, 0x94
{[]byte{0x04, 0x86, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff │ {[]byte{0x04, 0x4b, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff
{[]byte{0x04, 0x86, 0x00, 0x08, 0x01, 0x01, 0x00, 0x00, 0x04, 0x3B, 0x73 │ {[]byte{0x04, 0x4b, 0x00, 0x08, 0x01, 0x01, 0x00, 0x00, 0x04, 0x3B, 0x73
{[]byte{0x04, 0x86, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11}, "", │ {[]byte{0x04, 0x4b, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11}, "",
{[]byte{0xfe, 0xfe, 0x00, 0x07, 0x04, 0x3B, 0x73, 0x49, 0x05, 0x06, 0x07 │ {[]byte{0xfe, 0xfe, 0x00, 0x07, 0x04, 0x3B, 0x73, 0x49, 0x05, 0x06, 0x07
} │ }
│
for _, test := range tests { │ for _, test := range tests {
tlv := LsTLVPrefixSID{} │ tlv := LsTLVAdjacencySID{}
if test.err { │ if test.err {
assert.Error(tlv.DecodeFromBytes(test.in)) │ assert.Error(tlv.DecodeFromBytes(test.in))
continue │ continue
} else { │ } else {
assert.NoError(tlv.DecodeFromBytes(test.in)) │ assert.NoError(tlv.DecodeFromBytes(test.in))
} │ }
│
got, err := tlv.MarshalJSON() │ got, err := tlv.MarshalJSON()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(got, []byte(test.want)) │ assert.Equal(got, []byte(test.want))
│
if test.serialize { │ if test.serialize {
s, err := tlv.Serialize() │ s, err := tlv.Serialize()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(test.in, s) │ assert.Equal(test.in, s)
} │ }
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:700 │ gobgp/pkg/apiutil/attribute_test.go:788
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rt, err := apb.New(&api.IPv4AddressSpecificExtended{
Admin: "1.1.1.1", │ IsTransitive: true,
Assigned: 100, │ SubType: 0x02, // Route Target
│ Address: "1.1.1.1",
│ LocalAdmin: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ a, err := apb.New(&api.RouteTargetMembershipNLRI{
Labels: []uint32{100, 200}, │ Asn: 65000,
Rd: rd, │ Rt: rt,
PrefixLen: 24, │
Prefix: "192.168.101.0", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:788
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rt, err := apb.New(&api.IPv4AddressSpecificExtended{
Admin: "1.1.1.1", │ IsTransitive: true,
Assigned: 100, │ SubType: 0x02, // Route Target
│ Address: "1.1.1.1",
│ LocalAdmin: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ a, err := apb.New(&api.RouteTargetMembershipNLRI{
Labels: []uint32{100, 200}, │ Asn: 65000,
Rd: rd, │ Rt: rt,
PrefixLen: 64, │
Prefix: "2001:db8:1::", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:744 │ gobgp/pkg/apiutil/attribute_test.go:700
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherIPAddress{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: "1.1.1.1", │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.LabeledVPNIPAddressPrefix{ │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
Labels: []uint32{100, 200}, │ Labels: []uint32{100, 200},
Rd: rd, │ Rd: rd,
PrefixLen: 64, │ PrefixLen: 24,
Prefix: "2001:db8:1::", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_VPN, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:559 │ gobgp/pkg/apiutil/attribute_test.go:509
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherFourOctetASN{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: 65000, │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.EVPNInclusiveMulticastEthernetTagRoute{ │ esi := &api.EthernetSegmentIdentifier{
│ Type: 0,
│ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNMACIPAdvertisementRoute{
Rd: rd, │ Rd: rd,
│ Esi: esi,
EthernetTag: 100, │ EthernetTag: 100,
│ MacAddress: "aa:bb:cc:dd:ee:ff",
IpAddress: "192.168.101.1", │ IpAddress: "192.168.101.1",
│ Labels: []uint32{200},
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:559 │ gobgp/pkg/apiutil/attribute_test.go:649
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherFourOctetASN{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: 65000, │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.EVPNInclusiveMulticastEthernetTagRoute{ │ esi := &api.EthernetSegmentIdentifier{
│ Type: 0,
│ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNIPPrefixRoute{
Rd: rd, │ Rd: rd,
│ Esi: esi,
EthernetTag: 100, │ EthernetTag: 100,
IpAddress: "192.168.101.1", │ IpPrefixLen: 24,
│ IpPrefix: "192.168.101.0",
│ Label: 200,
│ GwAddress: "172.16.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:559 │ gobgp/pkg/apiutil/attribute_test.go:461
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherFourOctetASN{ │ rd, err := apb.New(&api.RouteDistinguisherTwoOctetASN{
Admin: 65000, │ Admin: 65000,
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.EVPNInclusiveMulticastEthernetTagRoute{ │ esi := &api.EthernetSegmentIdentifier{
│ Type: 0,
│ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNEthernetAutoDiscoveryRoute{
Rd: rd, │ Rd: rd,
│ Esi: esi,
EthernetTag: 100, │ EthernetTag: 100,
IpAddress: "192.168.101.1", │ Label: 200,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:559 │ gobgp/pkg/apiutil/attribute_test.go:602
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 1) │ nlris := make([]*apb.Any, 0, 1)
rd, err := apb.New(&api.RouteDistinguisherFourOctetASN{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Admin: 65000, │ Admin: "1.1.1.1",
Assigned: 100, │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
a, err := apb.New(&api.EVPNInclusiveMulticastEthernetTagRoute{ │ esi := &api.EthernetSegmentIdentifier{
Rd: rd, │ Type: 0,
EthernetTag: 100, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
IpAddress: "192.168.101.1", │ }
│ a, err := apb.New(&api.EVPNEthernetSegmentRoute{
│ Rd: rd,
│ Esi: esi,
│ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_L2VPN, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(1, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:246 │ gobgp/pkg/apiutil/attribute_test.go:602
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
PrefixLen: 64, │ Admin: "1.1.1.1",
Prefix: "2001:db8:1::", │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ esi := &api.EthernetSegmentIdentifier{
a, err = apb.New(&api.IPAddressPrefix{ │ Type: 0,
PrefixLen: 64, │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
Prefix: "2001:db8:2::", │ }
│ a, err := apb.New(&api.EVPNEthernetSegmentRoute{
│ Rd: rd,
│ Esi: esi,
│ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"2001:db8::1", "fe80::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:246 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.IPAddressPrefix{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
PrefixLen: 64, │ Labels: []uint32{100},
Prefix: "2001:db8:1::", │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.IPAddressPrefix{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
PrefixLen: 64, │ Labels: []uint32{200},
Prefix: "2001:db8:2::", │ PrefixLen: 24,
│ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1", "fe80::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:246 │ gobgp/pkg/apiutil/attribute_test.go:334
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.IPAddressPrefix{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
│ Labels: []uint32{100},
PrefixLen: 64, │ PrefixLen: 64,
Prefix: "2001:db8:1::", │ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.IPAddressPrefix{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
│ Labels: []uint32{200},
PrefixLen: 64, │ PrefixLen: 64,
Prefix: "2001:db8:2::", │ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1", "fe80::1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:246 │ gobgp/pkg/apiutil/attribute_test.go:788
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rt, err := apb.New(&api.IPv4AddressSpecificExtended{
PrefixLen: 64, │ IsTransitive: true,
Prefix: "2001:db8:1::", │ SubType: 0x02, // Route Target
│ Address: "1.1.1.1",
│ LocalAdmin: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.RouteTargetMembershipNLRI{
a, err = apb.New(&api.IPAddressPrefix{ │ Asn: 65000,
PrefixLen: 64, │ Rt: rt,
Prefix: "2001:db8:2::", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}, │ },
NextHops: []string{"2001:db8::1", "fe80::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:246 │ gobgp/pkg/apiutil/attribute_test.go:700
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
PrefixLen: 64, │ Admin: "1.1.1.1",
Prefix: "2001:db8:1::", │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.IPAddressPrefix{ │ Labels: []uint32{100, 200},
PrefixLen: 64, │ Rd: rd,
Prefix: "2001:db8:2::", │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"2001:db8::1", "fe80::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:246 │ gobgp/pkg/apiutil/attribute_test.go:744
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
PrefixLen: 64, │ Admin: "1.1.1.1",
Prefix: "2001:db8:1::", │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.IPAddressPrefix{ │ Labels: []uint32{100, 200},
│ Rd: rd,
PrefixLen: 64, │ PrefixLen: 64,
Prefix: "2001:db8:2::", │ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"2001:db8::1", "fe80::1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/internal/pkg/table/path_test.go:175 │ gobgp/internal/pkg/table/path_test.go:204
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
│
│ asns := make([]uint16, 255)
│ for i := range asns {
│ asns[i] = 65000 + uint16(i)
│ }
│
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{}), │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│
asn := uint32(65000) │ expected := []uint32{65000, 65000}
p.PrependAsn(asn, 1, false) │ for _, v := range asns {
assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) │ expected = append(expected, uint32(v))
│ }
│ p.PrependAsn(65000, 2, false)
│ assert.Equal(append(expected, []uint32{0, 0, 0}...), p.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/path_test.go:175 │ gobgp/internal/pkg/table/path_test.go:97
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{}), │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│
asn := uint32(65000) │ p.PrependAsn(65000, 1, false)
p.PrependAsn(asn, 1, false) │ assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005, 0, 0, 0}, p.GetA
assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) │
} │
next prev up gobgp/internal/pkg/table/path_test.go:175 │ gobgp/internal/pkg/table/path_test.go:69
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{}), │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│ med := bgp.NewPathAttributeMultiExitDisc(0)
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
│ med,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│ assert.Equal(10, p.GetAsPathLen())
asn := uint32(65000) │
p.PrependAsn(asn, 1, false) │
assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) │
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.IPAddressPrefix{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
│ Labels: []uint32{100},
PrefixLen: 24, │ PrefixLen: 24,
Prefix: "192.168.101.0", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.IPAddressPrefix{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
│ Labels: []uint32{200},
PrefixLen: 24, │ PrefixLen: 24,
Prefix: "192.168.201.0", │ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:334
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.IPAddressPrefix{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
PrefixLen: 24, │ Labels: []uint32{100},
Prefix: "192.168.101.0", │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.IPAddressPrefix{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
PrefixLen: 24, │ Labels: []uint32{200},
Prefix: "192.168.201.0", │ PrefixLen: 64,
│ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:788
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rt, err := apb.New(&api.IPv4AddressSpecificExtended{
PrefixLen: 24, │ IsTransitive: true,
Prefix: "192.168.101.0", │ SubType: 0x02, // Route Target
│ Address: "1.1.1.1",
│ LocalAdmin: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.RouteTargetMembershipNLRI{
a, err = apb.New(&api.IPAddressPrefix{ │ Asn: 65000,
PrefixLen: 24, │ Rt: rt,
Prefix: "192.168.201.0", │
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:700
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
PrefixLen: 24, │ Admin: "1.1.1.1",
Prefix: "192.168.101.0", │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.IPAddressPrefix{ │ Labels: []uint32{100, 200},
│ Rd: rd,
PrefixLen: 24, │ PrefixLen: 24,
Prefix: "192.168.201.0", │ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:744
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
PrefixLen: 24, │ Admin: "1.1.1.1",
Prefix: "192.168.101.0", │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.IPAddressPrefix{ │ Labels: []uint32{100, 200},
PrefixLen: 24, │ Rd: rd,
Prefix: "192.168.201.0", │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:559
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.IPAddressPrefix{ │ rd, err := apb.New(&api.RouteDistinguisherFourOctetASN{
PrefixLen: 24, │ Admin: 65000,
Prefix: "192.168.101.0", │ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.EVPNInclusiveMulticastEthernetTagRoute{
a, err = apb.New(&api.IPAddressPrefix{ │ Rd: rd,
PrefixLen: 24, │ EthernetTag: 100,
Prefix: "192.168.201.0", │ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:203 │ gobgp/pkg/apiutil/attribute_test.go:246
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.IPAddressPrefix{ │ a, err := apb.New(&api.IPAddressPrefix{
PrefixLen: 24, │ PrefixLen: 64,
Prefix: "192.168.101.0", │ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.IPAddressPrefix{ │ a, err = apb.New(&api.IPAddressPrefix{
PrefixLen: 24, │ PrefixLen: 64,
Prefix: "192.168.201.0", │ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_UNICAST, │ Safi: api.Family_SAFI_UNICAST,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1", "fe80::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2992 │ gobgp/pkg/packet/bgp/bgp_test.go:2975
[]byte{ │ []byte{
0x00, 0x02, 0x00, 0x59, // Link NLRI, correct length │ 0x00, 0x02, 0x00, 0x81, // Link NLRI, correct length
0x02, // Protocol ISIS │ 0x02, // Protocol ISIS
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID │ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID
0x01, 0x00, 0x00, 0x22, // Local Node Desc │ 0x01, 0x00, 0x00, 0x22, // Local Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T │ 0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T
0x01, 0x01, 0x00, 0x22, // Remote Node Desc │ 0x01, 0x01, 0x00, 0x22, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T │ 0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T
│ 0x01, 0x06, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00
│ }, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.020
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2992 │ gobgp/pkg/packet/bgp/bgp_test.go:2958
[]byte{ │ []byte{
0x00, 0x02, 0x00, 0x59, // Link NLRI, correct length │ 0x00, 0x02, 0x00, 0x69, // Link NLRI, correct length
0x02, // Protocol ISIS │ 0x02, // Protocol ISIS
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID │ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID
0x01, 0x00, 0x00, 0x22, // Local Node Desc │ 0x01, 0x00, 0x00, 0x22, // Local Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T │ 0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T
0x01, 0x01, 0x00, 0x22, // Remote Node Desc │ 0x01, 0x01, 0x00, 0x22, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T │ 0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T
│ 0x01, 0x04, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, // IPv4 Neighbor
│ }, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.020
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2992 │ gobgp/pkg/packet/bgp/bgp_test.go:2942
[]byte{ │ []byte{
0x00, 0x02, 0x00, 0x59, // Link NLRI, correct length │ 0x00, 0x02, 0x00, 0x65, // Link NLRI, correct length
0x02, // Protocol ISIS │ 0x02, // Protocol ISIS
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID │ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ID
0x01, 0x00, 0x00, 0x22, // Local Node Desc │ 0x01, 0x00, 0x00, 0x22, // Local Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T │ 0x02, 0x03, 0x00, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // T
0x01, 0x01, 0x00, 0x22, // Remote Node Desc │ 0x01, 0x01, 0x00, 0x22, // Remote Node Desc
0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179 │ 0x02, 0x00, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV ASN: 1179
0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID │ 0x02, 0x01, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV BGP LS ID
0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area │ 0x02, 0x02, 0x00, 0x04, 0x07, 0x07, 0x07, 0x07, // TLV OSPF Area
0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T │ 0x02, 0x03, 0x00, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, // T
│ }, "NLRI { LINK { LOCAL_NODE: 0102.0304.0506 REMOTE_NODE: 0605.0403.020
next prev up gobgp/internal/pkg/table/policy_test.go:51 │ gobgp/internal/pkg/table/policy_test.go:117
│
// create path │ // create path
peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")} │ peer := &PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001}) │ aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1") │ nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0) │ med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med} │ pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.0.101")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
path := ProcessMessage(updateMsg, peer, time.Now())[0] │ path := ProcessMessage(updateMsg, peer, time.Now())[0]
// test │ // test
pl1, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/24", MasklengthRange: ""} │ pl1, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21
match1 := pl1.Match(path) │ match1 := pl1.Match(path)
assert.Equal(t, true, match1) │ assert.Equal(t, false, match1)
pl2, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/23", MasklengthRange: ""} │ pl2, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "25
match2 := pl2.Match(path) │ match2 := pl2.Match(path)
assert.Equal(t, false, match2) │ assert.Equal(t, false, match2)
pl3, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21 │ pl3, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21
match3 := pl3.Match(path) │ match3 := pl3.Match(path)
assert.Equal(t, true, match3) │ assert.Equal(t, true, match3)
} │
next prev up gobgp/pkg/packet/bgp/bgp.go:5478 │ gobgp/pkg/packet/bgp/bgp.go:5350
│
if err := l.LsNLRI.DecodeFromBytes(data); err != nil { │ if err := l.LsNLRI.DecodeFromBytes(data); err != nil {
return nil │ return nil
} │ }
│
tlv := data[lsNLRIHdrLen:] │ tlv := data[lsNLRIHdrLen:]
m := make(map[LsTLVType]bool) │ m := make(map[LsTLVType]bool)
│
for len(tlv) >= tlvHdrLen { │ for len(tlv) >= tlvHdrLen {
sub := &LsTLV{} │ sub := &LsTLV{}
_, err := sub.DecodeFromBytes(tlv) │ _, err := sub.DecodeFromBytes(tlv)
if err != nil { │ if err != nil {
return err │ return err
} │ }
m[sub.Type] = true │ m[sub.Type] = true
│
var subTLV LsTLVInterface │ var subTLV LsTLVInterface
switch sub.Type { │ switch sub.Type {
case LS_TLV_LOCAL_NODE_DESC: │ case LS_TLV_LOCAL_NODE_DESC:
subTLV = &LsTLVNodeDescriptor{} │ subTLV = &LsTLVNodeDescriptor{}
case LS_TLV_OSPF_ROUTE_TYPE: │ case LS_TLV_OSPF_ROUTE_TYPE:
subTLV = &LsTLVOspfRouteType{} │ subTLV = &LsTLVOspfRouteType{}
case LS_TLV_IP_REACH_INFO: │ case LS_TLV_IP_REACH_INFO:
subTLV = &LsTLVIPReachability{} │ subTLV = &LsTLVIPReachability{}
│
default: │ default:
tlv = tlv[sub.Len():] │ tlv = tlv[sub.Len():]
l.Length -= uint16(sub.Len()) │ l.Length -= uint16(sub.Len())
continue │ continue
} │ }
│
if err := subTLV.DecodeFromBytes(tlv); err != nil { │ if err := subTLV.DecodeFromBytes(tlv); err != nil {
return err │ return err
} │ }
tlv = tlv[subTLV.Len():] │ tlv = tlv[subTLV.Len():]
│
switch sub.Type { │ switch sub.Type {
case LS_TLV_LOCAL_NODE_DESC: │ case LS_TLV_LOCAL_NODE_DESC:
l.LocalNodeDesc = subTLV │ l.LocalNodeDesc = subTLV
default: │ default:
l.PrefixDesc = append(l.PrefixDesc, subTLV) │ l.PrefixDesc = append(l.PrefixDesc, subTLV)
} │ }
} │ }
│
required := []LsTLVType{LS_TLV_IP_REACH_INFO, LS_TLV_LOCAL_NODE_DESC} │ required := []LsTLVType{LS_TLV_IP_REACH_INFO, LS_TLV_LOCAL_NODE_DESC}
for _, tlv := range required { │ for _, tlv := range required {
if _, ok := m[tlv]; !ok { │ if _, ok := m[tlv]; !ok {
return malformedAttrListErr("Required TLV missing") │ return malformedAttrListErr("Required TLV missing")
} │ }
} │ }
│
│ for _, tlv := range l.PrefixDesc {
│ switch v := tlv.(type) {
│ case *LsTLVIPReachability:
│ if v.PrefixLength > 8*net.IPv4len {
│ return malformedAttrListErr("Unexpected IP Reachability
│ }
│ }
│ }
│
return nil │ return nil
} │
next prev up gobgp/pkg/packet/bgp/bgp.go:7189 │ gobgp/pkg/packet/bgp/bgp.go:7075
│
value, err := l.LsTLV.DecodeFromBytes(data) │ value, err := l.LsTLV.DecodeFromBytes(data)
if err != nil { │ if err != nil {
return err │ return err
} │ }
│
if l.Type != LS_TLV_SR_LOCAL_BLOCK { │ if l.Type != LS_TLV_SR_CAPABILITIES {
return malformedAttrListErr("Unexpected TLV type") │ return malformedAttrListErr("Unexpected TLV type")
} │ }
│
if len(value) < 2 { │ if len(value) < 2 {
return malformedAttrListErr("Incorrect SR Local Block length") │ return malformedAttrListErr("Incorrect SR Capabilities length")
} │ }
l.Flags = value[0] │ l.Flags = value[0]
│
// Skip two bytes: flags and reserved. │ // Skip two bytes: flags and reserved.
value = value[2:] │ value = value[2:]
│
// The value field should be at least eight bytes long. Three bytes │ // The value field should be at least eight bytes long. Three bytes
// for the range size and five or six bytes for the SID/Label TLV. │ // for the range size and five or six bytes for the SID/Label TLV.
for len(value) > 8 { │ for len(value) > 8 {
// First, parse range size (3 bytes) │ // First, parse range size (3 bytes)
buf := []byte{0, 0, 0, 0} │ buf := []byte{0, 0, 0, 0}
for i := 1; i < len(buf); i++ { │ for i := 1; i < len(buf); i++ {
buf[i] = value[i-1] │ buf[i] = value[i-1]
} │ }
r := binary.BigEndian.Uint32(buf) │ r := binary.BigEndian.Uint32(buf)
value = value[3:] │ value = value[3:]
│
// Second, parse SID/Label sub-TLV. │ // Second, parse SID/Label sub-TLV.
label := LsTLVSIDLabel{} │ label := LsTLVSIDLabel{}
if err := label.DecodeFromBytes(value); err != nil { │ if err := label.DecodeFromBytes(value); err != nil {
return err │ return err
} │ }
│
l.Ranges = append(l.Ranges, LsSrLabelRange{ │ l.Ranges = append(l.Ranges, LsSrLabelRange{
Range: r, │ Range: r,
FirstLabel: label, │ FirstLabel: label,
}) │ })
│
value = value[label.Len():] │ value = value[label.Len():]
} │ }
│
if len(value) > 0 { │ if len(value) > 0 {
return malformedAttrListErr("Malformed SR Local Block TLV") │ return malformedAttrListErr("Malformed SR Capabilities TLV")
} │ }
│
return nil │ return nil
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Address: "2001:db8:1::1", │ Labels: []uint32{100},
│ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Address: "2001:db8:2::1", │ Labels: []uint32{200},
│ PrefixLen: 24,
│ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:334
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Address: "2001:db8:1::1", │ Labels: []uint32{100},
│ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Address: "2001:db8:2::1", │ Labels: []uint32{200},
│ PrefixLen: 64,
│ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:788
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rt, err := apb.New(&api.IPv4AddressSpecificExtended{
Address: "2001:db8:1::1", │ IsTransitive: true,
│ SubType: 0x02, // Route Target
│ Address: "1.1.1.1",
│ LocalAdmin: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.RouteTargetMembershipNLRI{
a, err = apb.New(&api.EncapsulationNLRI{ │ Asn: 65000,
Address: "2001:db8:2::1", │ Rt: rt,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:700
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Address: "2001:db8:1::1", │ Admin: "1.1.1.1",
│ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.EncapsulationNLRI{ │ Labels: []uint32{100, 200},
Address: "2001:db8:2::1", │ Rd: rd,
│ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:744
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Address: "2001:db8:1::1", │ Admin: "1.1.1.1",
│ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.EncapsulationNLRI{ │ Labels: []uint32{100, 200},
Address: "2001:db8:2::1", │ Rd: rd,
│ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:246
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.IPAddressPrefix{
Address: "2001:db8:1::1", │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.IPAddressPrefix{
Address: "2001:db8:2::1", │ PrefixLen: 64,
│ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_UNICAST,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"2001:db8::1", "fe80::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:420 │ gobgp/pkg/apiutil/attribute_test.go:203
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.IPAddressPrefix{
Address: "2001:db8:1::1", │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.IPAddressPrefix{
Address: "2001:db8:2::1", │ PrefixLen: 24,
│ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP6, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_UNICAST,
}, │ },
NextHops: []string{"2001:db8::1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:602
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Address: "192.168.101.1", │ Admin: "1.1.1.1",
│ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ esi := &api.EthernetSegmentIdentifier{
a, err = apb.New(&api.EncapsulationNLRI{ │ Type: 0,
Address: "192.168.201.1", │ Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
│ }
│ a, err := apb.New(&api.EVPNEthernetSegmentRoute{
│ Rd: rd,
│ Esi: esi,
│ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:289
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Address: "192.168.101.1", │ Labels: []uint32{100},
│ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Address: "192.168.201.1", │ Labels: []uint32{200},
│ PrefixLen: 24,
│ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:334
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.LabeledIPAddressPrefix{
Address: "192.168.101.1", │ Labels: []uint32{100},
│ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.LabeledIPAddressPrefix{
Address: "192.168.201.1", │ Labels: []uint32{200},
│ PrefixLen: 64,
│ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_LABEL,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:788
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rt, err := apb.New(&api.IPv4AddressSpecificExtended{
Address: "192.168.101.1", │ IsTransitive: true,
│ SubType: 0x02, // Route Target
│ Address: "1.1.1.1",
│ LocalAdmin: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.RouteTargetMembershipNLRI{
a, err = apb.New(&api.EncapsulationNLRI{ │ Asn: 65000,
Address: "192.168.201.1", │ Rt: rt,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:700
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Address: "192.168.101.1", │ Admin: "1.1.1.1",
│ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.EncapsulationNLRI{ │ Labels: []uint32{100, 200},
Address: "192.168.201.1", │ Rd: rd,
│ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:744
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rd, err := apb.New(&api.RouteDistinguisherIPAddress{
Address: "192.168.101.1", │ Admin: "1.1.1.1",
│ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.LabeledVPNIPAddressPrefix{
a, err = apb.New(&api.EncapsulationNLRI{ │ Labels: []uint32{100, 200},
Address: "192.168.201.1", │ Rd: rd,
│ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_MPLS_VPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:559
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 1)
a, err := apb.New(&api.EncapsulationNLRI{ │ rd, err := apb.New(&api.RouteDistinguisherFourOctetASN{
Address: "192.168.101.1", │ Admin: 65000,
│ Assigned: 100,
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ a, err := apb.New(&api.EVPNInclusiveMulticastEthernetTagRoute{
a, err = apb.New(&api.EncapsulationNLRI{ │ Rd: rd,
Address: "192.168.201.1", │ EthernetTag: 100,
│ IpAddress: "192.168.101.1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_EVPN,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(1, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:246
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.IPAddressPrefix{
Address: "192.168.101.1", │ PrefixLen: 64,
│ Prefix: "2001:db8:1::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.IPAddressPrefix{
Address: "192.168.201.1", │ PrefixLen: 64,
│ Prefix: "2001:db8:2::",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_UNICAST,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1", "fe80::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:203
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.IPAddressPrefix{
Address: "192.168.101.1", │ PrefixLen: 24,
│ Prefix: "192.168.101.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.IPAddressPrefix{
Address: "192.168.201.1", │ PrefixLen: 24,
│ Prefix: "192.168.201.0",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_UNICAST,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"192.168.1.1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:379 │ gobgp/pkg/apiutil/attribute_test.go:420
│
assert := assert.New(t) │ assert := assert.New(t)
│
nlris := make([]*apb.Any, 0, 2) │ nlris := make([]*apb.Any, 0, 2)
a, err := apb.New(&api.EncapsulationNLRI{ │ a, err := apb.New(&api.EncapsulationNLRI{
Address: "192.168.101.1", │ Address: "2001:db8:1::1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
a, err = apb.New(&api.EncapsulationNLRI{ │ a, err = apb.New(&api.EncapsulationNLRI{
Address: "192.168.201.1", │ Address: "2001:db8:2::1",
}) │ })
assert.Nil(err) │ assert.Nil(err)
nlris = append(nlris, a) │ nlris = append(nlris, a)
│
input := &api.MpReachNLRIAttribute{ │ input := &api.MpReachNLRIAttribute{
Family: &api.Family{ │ Family: &api.Family{
Afi: api.Family_AFI_IP, │ Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION, │ Safi: api.Family_SAFI_ENCAPSULATION,
}, │ },
NextHops: []string{"192.168.1.1"}, │ NextHops: []string{"2001:db8::1"},
Nlris: nlris, │ Nlris: nlris,
} │ }
│
a, err = apb.New(input) │ a, err = apb.New(input)
assert.Nil(err) │ assert.Nil(err)
n, err := UnmarshalAttribute(a) │ n, err := UnmarshalAttribute(a)
assert.Nil(err) │ assert.Nil(err)
│
output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI) │ output, _ := NewMpReachNLRIAttributeFromNative(n.(*bgp.PathAttributeMpReachNLRI)
assert.Equal(input.Family.Afi, output.Family.Afi) │ assert.Equal(input.Family.Afi, output.Family.Afi)
assert.Equal(input.Family.Safi, output.Family.Safi) │ assert.Equal(input.Family.Safi, output.Family.Safi)
assert.Equal(input.NextHops, output.NextHops) │ assert.Equal(input.NextHops, output.NextHops)
assert.Equal(2, len(output.Nlris)) │ assert.Equal(2, len(output.Nlris))
for idx, inputNLRI := range input.Nlris { │ for idx, inputNLRI := range input.Nlris {
outputNLRI := output.Nlris[idx] │ outputNLRI := output.Nlris[idx]
assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl) │ assert.Equal(inputNLRI.TypeUrl, outputNLRI.TypeUrl)
assert.Equal(inputNLRI.Value, outputNLRI.Value) │ assert.Equal(inputNLRI.Value, outputNLRI.Value)
} │ }
} │
next prev up gobgp/pkg/packet/bgp/bgp_test.go:2070 │ gobgp/pkg/packet/bgp/bgp_test.go:2103
│
assert := assert.New(t) │ assert := assert.New(t)
│
var tests = []struct { │ var tests = []struct {
in []byte │ in []byte
want string │ want string
err bool │ err bool
}{ │ }{
{[]byte{0x04, 0x41, 0x00, 0x04, 0x43, 0xA4, 0xB2, 0x00}, `{"type":1089," │ {[]byte{0x04, 0x42, 0x00, 0x04, 0x43, 0xA4, 0xB2, 0x00}, `{"type":1090,"
{[]byte{0x04, 0x41, 0x00, 0x04, 0x43, 0xA4, 0xB2, 0x00, 0xFF}, `{"type": │ {[]byte{0x04, 0x42, 0x00, 0x04, 0x43, 0xA4, 0xB2, 0x00, 0xFF}, `{"type":
{[]byte{0x04, 0x41, 0x00, 0x03, 0x07, 0x07, 0x07}, "", true}, │ {[]byte{0x04, 0x42, 0x00, 0x03, 0x07, 0x07, 0x07}, "", true},
{[]byte{0x04, 0x41, 0x00, 0x04, 0x7f, 0x80, 0x00, 0x00}, "", true}, // + │ {[]byte{0x04, 0x42, 0x00, 0x04, 0x7f, 0x80, 0x00, 0x00}, "", true}, // +
{[]byte{0x04, 0x41, 0x00, 0x04, 0xff, 0x80, 0x00, 0x00}, "", true}, // - │ {[]byte{0x04, 0x42, 0x00, 0x04, 0xff, 0x80, 0x00, 0x00}, "", true}, // -
{[]byte{0x04, 0x41, 0x00, 0x04, 0xff, 0xbf, 0xff, 0xff}, "", true}, // N │ {[]byte{0x04, 0x42, 0x00, 0x04, 0xff, 0xbf, 0xff, 0xff}, "", true}, // N
{[]byte{0x04, 0x41, 0x00, 0x04, 0xc2, 0xc8, 0x00, 0x00}, "", true}, // - │ {[]byte{0x04, 0x42, 0x00, 0x04, 0xc2, 0xc8, 0x00, 0x00}, "", true}, // -
{[]byte{0xfe, 0xfe, 0x00, 0x00}, "", true}, │ {[]byte{0xfe, 0xfe, 0x00, 0x00}, "", true},
} │ }
│
for _, test := range tests { │ for _, test := range tests {
tlv := LsTLVMaxLinkBw{} │ tlv := LsTLVMaxReservableLinkBw{}
if test.err { │ if test.err {
assert.Error(tlv.DecodeFromBytes(test.in)) │ assert.Error(tlv.DecodeFromBytes(test.in))
continue │ continue
} else { │ } else {
assert.NoError(tlv.DecodeFromBytes(test.in)) │ assert.NoError(tlv.DecodeFromBytes(test.in))
} │ }
│
got, err := tlv.MarshalJSON() │ got, err := tlv.MarshalJSON()
assert.NoError(err) │ assert.NoError(err)
assert.Equal(got, []byte(test.want)) │ assert.Equal(got, []byte(test.want))
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:1629 │ gobgp/pkg/apiutil/attribute_test.go:1595
│
tests := []struct { │ tests := []struct {
name string │ name string
input []byte │ input []byte
}{ │ }{
{ │ {
name: "srv6 prefix sid", │ name: "srv6 prefix sid",
input: []byte{0x01, 0x00, 0x06, 0x28, 0x18, 0x10, 0x00, 0x10, 0x │ input: []byte{0xc0, 0x28, 0x25, 0x05, 0x00, 0x22, 0x00, 0x01, 0x
}, │ },
} │ }
for _, tt := range tests { │ for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { │ t.Run(tt.name, func(t *testing.T) {
sstlv := bgp.SRv6SIDStructureSubSubTLV{} │ attribute := bgp.PathAttributePrefixSID{}
if err := sstlv.DecodeFromBytes(tt.input); err != nil { │ if err := attribute.DecodeFromBytes(tt.input); err != nil {
t.Fatalf("test failed with error: %+v", err) │ t.Fatalf("test failed with error: %+v", err)
} │ }
// Converting from Native to API │ // Converting from Native to API
apiPrefixSID, _ := MarshalSRv6SubSubTLVs([]bgp.PrefixSIDTLVInter │ apiPrefixSID, _ := NewPrefixSIDAttributeFromNative(&attribute)
// Converting back from API to Native │ // Converting back from API to Native
_, recoveredPrefixSID, err := UnmarshalSubSubTLVs(apiPrefixSID) │ recoveredPrefixSID, err := UnmarshalPrefixSID(apiPrefixSID)
if err != nil { │ if err != nil {
t.Fatalf("test failed with error: %+v", err) │ t.Fatalf("test failed with error: %+v", err)
} │ }
recovered, err := recoveredPrefixSID[0].Serialize() │ recovered, err := recoveredPrefixSID.Serialize()
if err != nil { │ if err != nil {
t.Fatalf("test failed with error: %+v", err) │ t.Fatalf("test failed with error: %+v", err)
} │ }
if !bytes.Equal(tt.input, recovered) { │ if !bytes.Equal(tt.input, recovered) {
t.Fatalf("round trip conversion test failed as expected │ t.Fatalf("round trip conversion test failed as expected
} │ }
}) │ })
} │ }
} │
next prev up gobgp/pkg/apiutil/attribute_test.go:1629 │ gobgp/pkg/apiutil/attribute_test.go:1663
│
tests := []struct { │ tests := []struct {
name string │ name string
input []byte │ input []byte
}{ │ }{
{ │ {
name: "srv6 prefix sid", │ name: "srv6 prefix sid informationw sub tlv",
input: []byte{0x01, 0x00, 0x06, 0x28, 0x18, 0x10, 0x00, 0x10, 0x │ input: []byte{0x01, 0x00, 0x1e, 0x00, 0x20, 0x01, 0x00, 0x00, 0x
}, │ },
} │ }
for _, tt := range tests { │ for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { │ t.Run(tt.name, func(t *testing.T) {
sstlv := bgp.SRv6SIDStructureSubSubTLV{} │ stlv := bgp.SRv6InformationSubTLV{}
if err := sstlv.DecodeFromBytes(tt.input); err != nil { │ if err := stlv.DecodeFromBytes(tt.input); err != nil {
t.Fatalf("test failed with error: %+v", err) │ t.Fatalf("test failed with error: %+v", err)
} │ }
// Converting from Native to API │ // Converting from Native to API
apiPrefixSID, _ := MarshalSRv6SubSubTLVs([]bgp.PrefixSIDTLVInter │ apiPrefixSID, _ := MarshalSRv6SubTLVs([]bgp.PrefixSIDTLVInterfac
// Converting back from API to Native │ // Converting back from API to Native
_, recoveredPrefixSID, err := UnmarshalSubSubTLVs(apiPrefixSID) │ _, recoveredPrefixSID, err := UnmarshalSubTLVs(apiPrefixSID)
if err != nil { │ if err != nil {
t.Fatalf("test failed with error: %+v", err) │ t.Fatalf("test failed with error: %+v", err)
} │ }
recovered, err := recoveredPrefixSID[0].Serialize() │ recovered, err := recoveredPrefixSID[0].Serialize()
if err != nil { │ if err != nil {
t.Fatalf("test failed with error: %+v", err) │ t.Fatalf("test failed with error: %+v", err)
} │ }
if !bytes.Equal(tt.input, recovered) { │ if !bytes.Equal(tt.input, recovered) {
t.Fatalf("round trip conversion test failed as expected │ t.Fatalf("round trip conversion test failed as expected
} │ }
}) │ })
} │ }
} │
next prev up gobgp/internal/pkg/table/path_test.go:147 │ gobgp/internal/pkg/table/path_test.go:204
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
│
│ asns := make([]uint16, 255)
│ for i := range asns {
│ asns[i] = 65000 + uint16(i)
│ }
│
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│
asn := uint32(65000) │ expected := []uint32{65000, 65000}
p.PrependAsn(asn, 1, false) │ for _, v := range asns {
assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) │ expected = append(expected, uint32(v))
│ }
│ p.PrependAsn(65000, 2, false)
│ assert.Equal(append(expected, []uint32{0, 0, 0}...), p.GetAsSeqList())
} │
next prev up gobgp/internal/pkg/table/path_test.go:147 │ gobgp/internal/pkg/table/path_test.go:97
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│
asn := uint32(65000) │ p.PrependAsn(65000, 1, false)
p.PrependAsn(asn, 1, false) │ assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005, 0, 0, 0}, p.GetA
assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) │
} │
next prev up gobgp/internal/pkg/table/path_test.go:147 │ gobgp/internal/pkg/table/path_test.go:175
│
assert := assert.New(t) │ assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0) │ origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{ │ aspathParam := []bgp.AsPathParamInterface{
│ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100,
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, │ bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100,
aspath := bgp.NewPathAttributeAsPath(aspathParam) │ aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1") │ nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
│
pathAttributes := []bgp.PathAttributeInterface{ │ pathAttributes := []bgp.PathAttributeInterface{
origin, │ origin,
aspath, │ aspath,
nexthop, │ nexthop,
} │ }
│
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")} │ nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) │ bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate) │ update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(logger, update) │ UpdatePathAttrs4ByteAs(logger, update)
peer := PathCreatePeer() │ peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), │ p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(),
│
asn := uint32(65000) │ asn := uint32(65000)
p.PrependAsn(asn, 1, false) │ p.PrependAsn(asn, 1, false)
assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList()) │ assert.Equal([]uint32{asn, 0, 0, 0}, p.GetAsSeqList())
} │