From 345e8eca5a26521932fea3accf7964673d190def Mon Sep 17 00:00:00 2001 From: wenovus Date: Tue, 24 Oct 2023 10:30:08 -0700 Subject: [PATCH] Update to latest version of GoBGP. Still one more PR that requires merging from upstream. This verifies that newly merged PRs from upstream work. --- bgp/BUILD | 4 +- bgp/config.go | 42 +++--- bgp/config_test.go | 328 ++++++++++++++++++++++----------------------- bgp/gobgp.go | 6 +- bgp/ocgobgp.go | 110 +++++++-------- go.mod | 2 +- go.sum | 4 +- repositories.bzl | 4 +- 8 files changed, 250 insertions(+), 250 deletions(-) diff --git a/bgp/BUILD b/bgp/BUILD index d6c19ce0..0ce34e74 100644 --- a/bgp/BUILD +++ b/bgp/BUILD @@ -21,7 +21,7 @@ go_library( "@com_github_openconfig_ygot//ygot", "@com_github_wenovus_gobgp_v3//api", "@com_github_wenovus_gobgp_v3//pkg/config", - "@com_github_wenovus_gobgp_v3//pkg/config/gobgp", + "@com_github_wenovus_gobgp_v3//pkg/config/oc", "@com_github_wenovus_gobgp_v3//pkg/server", "@com_github_wenovus_gobgp_v3//pkg/zebra", "@org_golang_x_exp//maps", @@ -41,6 +41,6 @@ go_test( "//gnmi/oc", "@com_github_google_go_cmp//cmp", "@com_github_openconfig_ygot//ygot", - "@com_github_wenovus_gobgp_v3//pkg/config/gobgp", + "@com_github_wenovus_gobgp_v3//pkg/config/oc", ], ) diff --git a/bgp/config.go b/bgp/config.go index fef6037b..1f947860 100644 --- a/bgp/config.go +++ b/bgp/config.go @@ -22,7 +22,7 @@ import ( log "github.com/golang/glog" "github.com/openconfig/lemming/gnmi/oc" - "github.com/wenovus/gobgp/v3/pkg/config/gobgp" + gobgpoc "github.com/wenovus/gobgp/v3/pkg/config/oc" "github.com/wenovus/gobgp/v3/pkg/zebra" ) @@ -31,8 +31,8 @@ import ( // GoBGP's notion of config vs. state does not conform to OpenConfig (see // https://github.com/osrg/gobgp/issues/2584) // Therefore, we need a compatibility layer between the two configs. -func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.RoutingPolicy, zapiURL string, listenPort uint16) *gobgp.BgpConfigSet { - bgpConfig := &gobgp.BgpConfigSet{} +func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.RoutingPolicy, zapiURL string, listenPort uint16) *gobgpoc.BgpConfigSet { + bgpConfig := &gobgpoc.BgpConfigSet{} // Global config global := bgpoc.GetOrCreateGlobal() @@ -49,20 +49,20 @@ func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.Routin for neighAddr, neigh := range bgpoc.Neighbor { // Add neighbour config. - bgpConfig.Neighbors = append(bgpConfig.Neighbors, gobgp.Neighbor{ - Config: gobgp.NeighborConfig{ + bgpConfig.Neighbors = append(bgpConfig.Neighbors, gobgpoc.Neighbor{ + Config: gobgpoc.NeighborConfig{ PeerAs: neigh.GetPeerAs(), NeighborAddress: neighAddr, }, // This is needed because GoBGP's configuration diffing // logic may check the state value instead of the // config value. - State: gobgp.NeighborState{ + State: gobgpoc.NeighborState{ PeerAs: neigh.GetPeerAs(), NeighborAddress: neighAddr, }, - Transport: gobgp.Transport{ - Config: gobgp.TransportConfig{ + Transport: gobgpoc.Transport{ + Config: gobgpoc.TransportConfig{ LocalAddress: neigh.GetTransport().GetLocalAddress(), RemotePort: neigh.GetNeighborPort(), }, @@ -72,7 +72,7 @@ func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.Routin intendedToGoBGPPolicies(bgpoc, policyoc, bgpConfig) - bgpConfig.Zebra.Config = gobgp.ZebraConfig{ + bgpConfig.Zebra.Config = gobgpoc.ZebraConfig{ Enabled: true, Url: zapiURL, // TODO(wenbli): This should actually be filled with the types @@ -88,7 +88,7 @@ func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.Routin } // intendedToGoBGPPolicies populates bgpConfig's policies from the OC configuration. -func intendedToGoBGPPolicies(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.RoutingPolicy, bgpConfig *gobgp.BgpConfigSet) { +func intendedToGoBGPPolicies(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.RoutingPolicy, bgpConfig *gobgpoc.BgpConfigSet) { var communitySetIndexMap map[string]int // community sets bgpConfig.DefinedSets.BgpDefinedSets.CommunitySets, communitySetIndexMap = convertCommunitySet(policyoc.GetOrCreateDefinedSets().GetOrCreateBgpDefinedSets().CommunitySet) @@ -118,7 +118,7 @@ func intendedToGoBGPPolicies(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *o // neigh2polA, neigh2polB, ..., ... // ...] // Global ApplyPolicy list: [same as policy-definitions] - bgpConfig.DefinedSets.NeighborSets = append(bgpConfig.DefinedSets.NeighborSets, gobgp.NeighborSet{ + bgpConfig.DefinedSets.NeighborSets = append(bgpConfig.DefinedSets.NeighborSets, gobgpoc.NeighborSet{ NeighborSetName: neighAddr, NeighborInfoList: []string{neighAddr}, }) @@ -155,31 +155,31 @@ func intendedToGoBGPPolicies(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *o // Create per-neighbour default policies. defaultImportPolicyName := "default-import|" + neighAddr defaultExportPolicyName := "default-export|" + neighAddr - bgpConfig.PolicyDefinitions = append(bgpConfig.PolicyDefinitions, gobgp.PolicyDefinition{ + bgpConfig.PolicyDefinitions = append(bgpConfig.PolicyDefinitions, gobgpoc.PolicyDefinition{ Name: defaultImportPolicyName, - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ // Use a customized name for the default policies. Name: defaultImportPolicyName, - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{ + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{ NeighborSet: neighAddr, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: defaultPolicyToRouteDisp(applyPolicy.Config.DefaultImportPolicy), }, }}, - }, gobgp.PolicyDefinition{ + }, gobgpoc.PolicyDefinition{ Name: defaultExportPolicyName, - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ // Use a customized name for the default policies. Name: defaultExportPolicyName, - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{ + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{ NeighborSet: neighAddr, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: defaultPolicyToRouteDisp(applyPolicy.Config.DefaultExportPolicy), }, }}, diff --git a/bgp/config_test.go b/bgp/config_test.go index c9b64c98..7abb9d1f 100644 --- a/bgp/config_test.go +++ b/bgp/config_test.go @@ -20,14 +20,14 @@ import ( "github.com/google/go-cmp/cmp" "github.com/openconfig/lemming/gnmi/fakedevice" "github.com/openconfig/lemming/gnmi/oc" - "github.com/wenovus/gobgp/v3/pkg/config/gobgp" + gobgpoc "github.com/wenovus/gobgp/v3/pkg/config/oc" ) func TestIntendedToGoBGPPolicies(t *testing.T) { tests := []struct { desc string inOC *oc.Root - wantBGPConfig *gobgp.BgpConfigSet + wantBGPConfig *gobgpoc.BgpConfigSet }{{ desc: "big-test", inOC: func() *oc.Root { @@ -86,10 +86,10 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { bgpoc.GetOrCreateNeighbor("2.2.2.2").GetOrCreateApplyPolicy().SetExportPolicy([]string{policyName}) return root }(), - wantBGPConfig: &gobgp.BgpConfigSet{ - Global: gobgp.Global{ - ApplyPolicy: gobgp.ApplyPolicy{ - Config: gobgp.ApplyPolicyConfig{ + wantBGPConfig: &gobgpoc.BgpConfigSet{ + Global: gobgpoc.Global{ + ApplyPolicy: gobgpoc.ApplyPolicy{ + Config: gobgpoc.ApplyPolicyConfig{ ImportPolicyList: []string{ "1.1.1.1|foo", "default-import|1.1.1.1", @@ -108,265 +108,265 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { }, }, }, - DefinedSets: gobgp.DefinedSets{ - PrefixSets: []gobgp.PrefixSet{{ + DefinedSets: gobgpoc.DefinedSets{ + PrefixSets: []gobgpoc.PrefixSet{{ PrefixSetName: "V4-1", - PrefixList: []gobgp.Prefix{{ + PrefixList: []gobgpoc.Prefix{{ IpPrefix: "10.10.10.0/27", MasklengthRange: "", }}, }, { PrefixSetName: "V4-2", - PrefixList: []gobgp.Prefix{{ + PrefixList: []gobgpoc.Prefix{{ IpPrefix: "10.20.0.0/16", MasklengthRange: "29..29", }}, }}, - NeighborSets: []gobgp.NeighborSet{{ + NeighborSets: []gobgpoc.NeighborSet{{ NeighborSetName: "1.1.1.1", NeighborInfoList: []string{"1.1.1.1"}, }, { NeighborSetName: "2.2.2.2", NeighborInfoList: []string{"2.2.2.2"}, }}, - BgpDefinedSets: gobgp.BgpDefinedSets{ - CommunitySets: []gobgp.CommunitySet{{ + BgpDefinedSets: gobgpoc.BgpDefinedSets{ + CommunitySets: []gobgpoc.CommunitySet{{ CommunitySetName: "COMM1", CommunityList: []string{"12345:54321"}, }}, }, }, - PolicyDefinitions: []gobgp.PolicyDefinition{{ + PolicyDefinitions: []gobgpoc.PolicyDefinition{{ Name: "1.1.1.1|foo", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "1.1.1.1|foo:foo-1", - Conditions: gobgp.Conditions{ + Conditions: gobgpoc.Conditions{ CallPolicy: "", - MatchPrefixSet: gobgp.MatchPrefixSet{PrefixSet: "V4-1", MatchSetOptions: "any"}, - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, MatchTagSet: gobgp.MatchTagSet{TagSet: "", MatchSetOptions: ""}, - InstallProtocolEq: "", IgpConditions: gobgp.IgpConditions{}, BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{PrefixSet: "V4-1", MatchSetOptions: "any"}, + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, MatchTagSet: gobgpoc.MatchTagSet{TagSet: "", MatchSetOptions: ""}, + InstallProtocolEq: "", IgpConditions: gobgpoc.IgpConditions{}, BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: "", MatchSetOptions: "any", }, - MatchExtCommunitySet: gobgp.MatchExtCommunitySet{ + MatchExtCommunitySet: gobgpoc.MatchExtCommunitySet{ ExtCommunitySet: "", MatchSetOptions: "", }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, OriginEq: "", NextHopInList: []string(nil), - AfiSafiInList: []gobgp.AfiSafiType(nil), + AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, - CommunityCount: gobgp.CommunityCount{Operator: "", Value: 0x0}, - AsPathLength: gobgp.AsPathLength{Operator: "", Value: 0x0}, + CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0}, + AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0}, RouteType: "", RpkiValidationResult: "", - MatchLargeCommunitySet: gobgp.MatchLargeCommunitySet{ + MatchLargeCommunitySet: gobgpoc.MatchLargeCommunitySet{ LargeCommunitySet: "", MatchSetOptions: "", }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "none", - IgpActions: gobgp.IgpActions{SetTag: ""}, - BgpActions: gobgp.BgpActions{SetAsPathPrepend: gobgp.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, - SetCommunity: gobgp.SetCommunity{SetCommunityMethod: gobgp.SetCommunityMethod{CommunitiesList: []string{"12345:54321"}, CommunitySetRef: ""}, Options: "add"}, - SetExtCommunity: gobgp.SetExtCommunity{SetExtCommunityMethod: gobgp.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, + IgpActions: gobgpoc.IgpActions{SetTag: ""}, + BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, + SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string{"12345:54321"}, CommunitySetRef: ""}, Options: "add"}, + SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, SetRouteOrigin: "", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", - SetLargeCommunity: gobgp.SetLargeCommunity{SetLargeCommunityMethod: gobgp.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, + SetLargeCommunity: gobgpoc.SetLargeCommunity{SetLargeCommunityMethod: gobgpoc.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, }, }, }, { Name: "1.1.1.1|foo:foo-2", - Conditions: gobgp.Conditions{ + Conditions: gobgpoc.Conditions{ CallPolicy: "", - MatchPrefixSet: gobgp.MatchPrefixSet{PrefixSet: "V4-2", MatchSetOptions: "any"}, - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, MatchTagSet: gobgp.MatchTagSet{TagSet: "", MatchSetOptions: ""}, - InstallProtocolEq: "", IgpConditions: gobgp.IgpConditions{}, BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{PrefixSet: "V4-2", MatchSetOptions: "any"}, + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, MatchTagSet: gobgpoc.MatchTagSet{TagSet: "", MatchSetOptions: ""}, + InstallProtocolEq: "", IgpConditions: gobgpoc.IgpConditions{}, BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: "", MatchSetOptions: "any", }, - MatchExtCommunitySet: gobgp.MatchExtCommunitySet{ + MatchExtCommunitySet: gobgpoc.MatchExtCommunitySet{ ExtCommunitySet: "", MatchSetOptions: "", }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, OriginEq: "", NextHopInList: []string(nil), - AfiSafiInList: []gobgp.AfiSafiType(nil), + AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, - CommunityCount: gobgp.CommunityCount{Operator: "", Value: 0x0}, - AsPathLength: gobgp.AsPathLength{Operator: "", Value: 0x0}, + CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0}, + AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0}, RouteType: "", RpkiValidationResult: "", - MatchLargeCommunitySet: gobgp.MatchLargeCommunitySet{ + MatchLargeCommunitySet: gobgpoc.MatchLargeCommunitySet{ LargeCommunitySet: "", MatchSetOptions: "", }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "accept-route", - IgpActions: gobgp.IgpActions{SetTag: ""}, - BgpActions: gobgp.BgpActions{SetAsPathPrepend: gobgp.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, - SetCommunity: gobgp.SetCommunity{SetCommunityMethod: gobgp.SetCommunityMethod{CommunitiesList: []string(nil), CommunitySetRef: ""}, Options: "replace"}, - SetExtCommunity: gobgp.SetExtCommunity{SetExtCommunityMethod: gobgp.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, + IgpActions: gobgpoc.IgpActions{SetTag: ""}, + BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, + SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string(nil), CommunitySetRef: ""}, Options: "replace"}, + SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, SetRouteOrigin: "", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", - SetLargeCommunity: gobgp.SetLargeCommunity{SetLargeCommunityMethod: gobgp.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, + SetLargeCommunity: gobgpoc.SetLargeCommunity{SetLargeCommunityMethod: gobgpoc.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, }, }, }}, }, { Name: "default-import|1.1.1.1", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-import|1.1.1.1", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "accept-route", }, }}, }, { Name: "default-export|1.1.1.1", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-export|1.1.1.1", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, }, { Name: "2.2.2.2|foo", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "2.2.2.2|foo:foo-1", - Conditions: gobgp.Conditions{ + Conditions: gobgpoc.Conditions{ CallPolicy: "", - MatchPrefixSet: gobgp.MatchPrefixSet{PrefixSet: "V4-1", MatchSetOptions: "any"}, - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, MatchTagSet: gobgp.MatchTagSet{TagSet: "", MatchSetOptions: ""}, - InstallProtocolEq: "", IgpConditions: gobgp.IgpConditions{}, BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{PrefixSet: "V4-1", MatchSetOptions: "any"}, + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, MatchTagSet: gobgpoc.MatchTagSet{TagSet: "", MatchSetOptions: ""}, + InstallProtocolEq: "", IgpConditions: gobgpoc.IgpConditions{}, BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: "", MatchSetOptions: "any", }, - MatchExtCommunitySet: gobgp.MatchExtCommunitySet{ + MatchExtCommunitySet: gobgpoc.MatchExtCommunitySet{ ExtCommunitySet: "", MatchSetOptions: "", }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, OriginEq: "", NextHopInList: []string(nil), - AfiSafiInList: []gobgp.AfiSafiType(nil), + AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, - CommunityCount: gobgp.CommunityCount{Operator: "", Value: 0x0}, - AsPathLength: gobgp.AsPathLength{Operator: "", Value: 0x0}, + CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0}, + AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0}, RouteType: "", RpkiValidationResult: "", - MatchLargeCommunitySet: gobgp.MatchLargeCommunitySet{ + MatchLargeCommunitySet: gobgpoc.MatchLargeCommunitySet{ LargeCommunitySet: "", MatchSetOptions: "", }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "none", - IgpActions: gobgp.IgpActions{SetTag: ""}, - BgpActions: gobgp.BgpActions{SetAsPathPrepend: gobgp.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, - SetCommunity: gobgp.SetCommunity{SetCommunityMethod: gobgp.SetCommunityMethod{CommunitiesList: []string{"12345:54321"}, CommunitySetRef: ""}, Options: "add"}, - SetExtCommunity: gobgp.SetExtCommunity{SetExtCommunityMethod: gobgp.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, + IgpActions: gobgpoc.IgpActions{SetTag: ""}, + BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, + SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string{"12345:54321"}, CommunitySetRef: ""}, Options: "add"}, + SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, SetRouteOrigin: "", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", - SetLargeCommunity: gobgp.SetLargeCommunity{SetLargeCommunityMethod: gobgp.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, + SetLargeCommunity: gobgpoc.SetLargeCommunity{SetLargeCommunityMethod: gobgpoc.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, }, }, }, { Name: "2.2.2.2|foo:foo-2", - Conditions: gobgp.Conditions{ + Conditions: gobgpoc.Conditions{ CallPolicy: "", - MatchPrefixSet: gobgp.MatchPrefixSet{PrefixSet: "V4-2", MatchSetOptions: "any"}, - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, MatchTagSet: gobgp.MatchTagSet{TagSet: "", MatchSetOptions: ""}, - InstallProtocolEq: "", IgpConditions: gobgp.IgpConditions{}, BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{PrefixSet: "V4-2", MatchSetOptions: "any"}, + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, MatchTagSet: gobgpoc.MatchTagSet{TagSet: "", MatchSetOptions: ""}, + InstallProtocolEq: "", IgpConditions: gobgpoc.IgpConditions{}, BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: "", MatchSetOptions: "any", }, - MatchExtCommunitySet: gobgp.MatchExtCommunitySet{ + MatchExtCommunitySet: gobgpoc.MatchExtCommunitySet{ ExtCommunitySet: "", MatchSetOptions: "", }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, OriginEq: "", NextHopInList: []string(nil), - AfiSafiInList: []gobgp.AfiSafiType(nil), + AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, - CommunityCount: gobgp.CommunityCount{Operator: "", Value: 0x0}, - AsPathLength: gobgp.AsPathLength{Operator: "", Value: 0x0}, + CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0}, + AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0}, RouteType: "", RpkiValidationResult: "", - MatchLargeCommunitySet: gobgp.MatchLargeCommunitySet{ + MatchLargeCommunitySet: gobgpoc.MatchLargeCommunitySet{ LargeCommunitySet: "", MatchSetOptions: "", }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "accept-route", - IgpActions: gobgp.IgpActions{SetTag: ""}, - BgpActions: gobgp.BgpActions{SetAsPathPrepend: gobgp.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, - SetCommunity: gobgp.SetCommunity{SetCommunityMethod: gobgp.SetCommunityMethod{CommunitiesList: []string(nil), CommunitySetRef: ""}, Options: "replace"}, - SetExtCommunity: gobgp.SetExtCommunity{SetExtCommunityMethod: gobgp.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, + IgpActions: gobgpoc.IgpActions{SetTag: ""}, + BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, + SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string(nil), CommunitySetRef: ""}, Options: "replace"}, + SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, SetRouteOrigin: "", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", - SetLargeCommunity: gobgp.SetLargeCommunity{SetLargeCommunityMethod: gobgp.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, + SetLargeCommunity: gobgpoc.SetLargeCommunity{SetLargeCommunityMethod: gobgpoc.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, }, }, }}, }, { Name: "default-import|2.2.2.2", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-import|2.2.2.2", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, }, { Name: "default-export|2.2.2.2", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-export|2.2.2.2", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, @@ -434,10 +434,10 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { bgpoc.GetOrCreateNeighbor("2.2.2.2").GetOrCreateApplyPolicy().SetExportPolicy([]string{policy2Name}) return root }(), - wantBGPConfig: &gobgp.BgpConfigSet{ - Global: gobgp.Global{ - ApplyPolicy: gobgp.ApplyPolicy{ - Config: gobgp.ApplyPolicyConfig{ + wantBGPConfig: &gobgpoc.BgpConfigSet{ + Global: gobgpoc.Global{ + ApplyPolicy: gobgpoc.ApplyPolicy{ + Config: gobgpoc.ApplyPolicyConfig{ ImportPolicyList: []string{ "default-import|1.1.1.1", "default-import|2.2.2.2", @@ -455,167 +455,167 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { }, }, }, - DefinedSets: gobgp.DefinedSets{ - PrefixSets: []gobgp.PrefixSet{{ + DefinedSets: gobgpoc.DefinedSets{ + PrefixSets: []gobgpoc.PrefixSet{{ PrefixSetName: "prefixset-foo", - PrefixList: []gobgp.Prefix{{ + PrefixList: []gobgpoc.Prefix{{ IpPrefix: "10.0.0.0/10", MasklengthRange: "8..32", }}, }}, - NeighborSets: []gobgp.NeighborSet{{ + NeighborSets: []gobgpoc.NeighborSet{{ NeighborSetName: "1.1.1.1", NeighborInfoList: []string{"1.1.1.1"}, }, { NeighborSetName: "2.2.2.2", NeighborInfoList: []string{"2.2.2.2"}, }}, - BgpDefinedSets: gobgp.BgpDefinedSets{ - CommunitySets: []gobgp.CommunitySet{{ + BgpDefinedSets: gobgpoc.BgpDefinedSets{ + CommunitySets: []gobgpoc.CommunitySet{{ CommunitySetName: "COMM1", CommunityList: []string{"[0-9]+:[0-9]+"}, }}, }, }, - PolicyDefinitions: []gobgp.PolicyDefinition{{ + PolicyDefinitions: []gobgpoc.PolicyDefinition{{ Name: "1.1.1.1|foo", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "1.1.1.1|foo:stmt", - Conditions: gobgp.Conditions{ + Conditions: gobgpoc.Conditions{ CallPolicy: "", - MatchPrefixSet: gobgp.MatchPrefixSet{PrefixSet: "prefixset-foo", MatchSetOptions: "any"}, - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, MatchTagSet: gobgp.MatchTagSet{TagSet: "", MatchSetOptions: ""}, - InstallProtocolEq: "", IgpConditions: gobgp.IgpConditions{}, BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{PrefixSet: "prefixset-foo", MatchSetOptions: "any"}, + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, MatchTagSet: gobgpoc.MatchTagSet{TagSet: "", MatchSetOptions: ""}, + InstallProtocolEq: "", IgpConditions: gobgpoc.IgpConditions{}, BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: "", MatchSetOptions: "any", }, - MatchExtCommunitySet: gobgp.MatchExtCommunitySet{ + MatchExtCommunitySet: gobgpoc.MatchExtCommunitySet{ ExtCommunitySet: "", MatchSetOptions: "", }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, OriginEq: "", NextHopInList: []string(nil), - AfiSafiInList: []gobgp.AfiSafiType(nil), + AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, - CommunityCount: gobgp.CommunityCount{Operator: "", Value: 0x0}, - AsPathLength: gobgp.AsPathLength{Operator: "", Value: 0x0}, + CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0}, + AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0}, RouteType: "", RpkiValidationResult: "", - MatchLargeCommunitySet: gobgp.MatchLargeCommunitySet{ + MatchLargeCommunitySet: gobgpoc.MatchLargeCommunitySet{ LargeCommunitySet: "", MatchSetOptions: "", }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "none", - IgpActions: gobgp.IgpActions{SetTag: ""}, - BgpActions: gobgp.BgpActions{SetAsPathPrepend: gobgp.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, - SetCommunity: gobgp.SetCommunity{SetCommunityMethod: gobgp.SetCommunityMethod{CommunitiesList: []string{"11111:11111", "22222:22222"}, CommunitySetRef: ""}, Options: "add"}, - SetExtCommunity: gobgp.SetExtCommunity{SetExtCommunityMethod: gobgp.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, + IgpActions: gobgpoc.IgpActions{SetTag: ""}, + BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, + SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string{"11111:11111", "22222:22222"}, CommunitySetRef: ""}, Options: "add"}, + SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, SetRouteOrigin: "", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", - SetLargeCommunity: gobgp.SetLargeCommunity{SetLargeCommunityMethod: gobgp.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, + SetLargeCommunity: gobgpoc.SetLargeCommunity{SetLargeCommunityMethod: gobgpoc.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, }, }, }}, }, { Name: "default-import|1.1.1.1", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-import|1.1.1.1", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, }, { Name: "default-export|1.1.1.1", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-export|1.1.1.1", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "1.1.1.1", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, }, { Name: "2.2.2.2|bar", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "2.2.2.2|bar:stmt", - Conditions: gobgp.Conditions{ + Conditions: gobgpoc.Conditions{ CallPolicy: "", - MatchPrefixSet: gobgp.MatchPrefixSet{PrefixSet: "prefixset-foo", MatchSetOptions: "any"}, - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, MatchTagSet: gobgp.MatchTagSet{TagSet: "", MatchSetOptions: ""}, - InstallProtocolEq: "", IgpConditions: gobgp.IgpConditions{}, BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{PrefixSet: "prefixset-foo", MatchSetOptions: "any"}, + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, MatchTagSet: gobgpoc.MatchTagSet{TagSet: "", MatchSetOptions: ""}, + InstallProtocolEq: "", IgpConditions: gobgpoc.IgpConditions{}, BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: "", MatchSetOptions: "any", }, - MatchExtCommunitySet: gobgp.MatchExtCommunitySet{ + MatchExtCommunitySet: gobgpoc.MatchExtCommunitySet{ ExtCommunitySet: "", MatchSetOptions: "", }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: "", MatchSetOptions: "any", }, MedEq: 0x0, OriginEq: "", NextHopInList: []string(nil), - AfiSafiInList: []gobgp.AfiSafiType(nil), + AfiSafiInList: []gobgpoc.AfiSafiType(nil), LocalPrefEq: 0x0, - CommunityCount: gobgp.CommunityCount{Operator: "", Value: 0x0}, - AsPathLength: gobgp.AsPathLength{Operator: "", Value: 0x0}, + CommunityCount: gobgpoc.CommunityCount{Operator: "", Value: 0x0}, + AsPathLength: gobgpoc.AsPathLength{Operator: "", Value: 0x0}, RouteType: "", RpkiValidationResult: "", - MatchLargeCommunitySet: gobgp.MatchLargeCommunitySet{ + MatchLargeCommunitySet: gobgpoc.MatchLargeCommunitySet{ LargeCommunitySet: "", MatchSetOptions: "", }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "accept-route", - IgpActions: gobgp.IgpActions{SetTag: ""}, - BgpActions: gobgp.BgpActions{SetAsPathPrepend: gobgp.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, - SetCommunity: gobgp.SetCommunity{SetCommunityMethod: gobgp.SetCommunityMethod{CommunitiesList: []string{"[0-9]+:[0-9]+"}, CommunitySetRef: ""}, Options: "remove"}, - SetExtCommunity: gobgp.SetExtCommunity{SetExtCommunityMethod: gobgp.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, + IgpActions: gobgpoc.IgpActions{SetTag: ""}, + BgpActions: gobgpoc.BgpActions{SetAsPathPrepend: gobgpoc.SetAsPathPrepend{RepeatN: 0x0, As: "0"}, + SetCommunity: gobgpoc.SetCommunity{SetCommunityMethod: gobgpoc.SetCommunityMethod{CommunitiesList: []string{"[0-9]+:[0-9]+"}, CommunitySetRef: ""}, Options: "remove"}, + SetExtCommunity: gobgpoc.SetExtCommunity{SetExtCommunityMethod: gobgpoc.SetExtCommunityMethod{CommunitiesList: []string(nil), ExtCommunitySetRef: ""}, Options: ""}, SetRouteOrigin: "", SetLocalPref: 0x0, SetNextHop: "", SetMed: "", - SetLargeCommunity: gobgp.SetLargeCommunity{SetLargeCommunityMethod: gobgp.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, + SetLargeCommunity: gobgpoc.SetLargeCommunity{SetLargeCommunityMethod: gobgpoc.SetLargeCommunityMethod{CommunitiesList: []string(nil)}, Options: ""}, }, }, }}, }, { Name: "default-import|2.2.2.2", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-import|2.2.2.2", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, }, { Name: "default-export|2.2.2.2", - Statements: []gobgp.Statement{{ + Statements: []gobgpoc.Statement{{ Name: "default-export|2.2.2.2", - Conditions: gobgp.Conditions{ - MatchNeighborSet: gobgp.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, + Conditions: gobgpoc.Conditions{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{NeighborSet: "2.2.2.2", MatchSetOptions: ""}, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: "reject-route", }, }}, @@ -625,7 +625,7 @@ func TestIntendedToGoBGPPolicies(t *testing.T) { for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - gotBGPConfig := &gobgp.BgpConfigSet{} + gotBGPConfig := &gobgpoc.BgpConfigSet{} intendedToGoBGPPolicies( tt.inOC.GetOrCreateNetworkInstance(fakedevice.DefaultNetworkInstance).GetOrCreateProtocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, fakedevice.BGPRoutingProtocol).GetOrCreateBgp(), tt.inOC.GetOrCreateRoutingPolicy(), diff --git a/bgp/gobgp.go b/bgp/gobgp.go index 4aab85bb..be8b9306 100644 --- a/bgp/gobgp.go +++ b/bgp/gobgp.go @@ -33,7 +33,7 @@ import ( "github.com/openconfig/ygot/ygot" api "github.com/wenovus/gobgp/v3/api" "github.com/wenovus/gobgp/v3/pkg/config" - "github.com/wenovus/gobgp/v3/pkg/config/gobgp" + gobgpoc "github.com/wenovus/gobgp/v3/pkg/config/oc" "github.com/wenovus/gobgp/v3/pkg/server" ) @@ -107,7 +107,7 @@ type bgpTask struct { targetName string zapiURL string bgpServer *server.BgpServer - currentConfig *gobgp.BgpConfigSet + currentConfig *gobgpoc.BgpConfigSet listenPort uint16 bgpStarted bool @@ -184,7 +184,7 @@ func (t *bgpTask) start(_ context.Context, yclient *ygnmi.Client) error { } // Initialize values required for reconile to be called. - t.currentConfig = &gobgp.BgpConfigSet{} + t.currentConfig = &gobgpoc.BgpConfigSet{} // Monitor changes to BGP intended config and apply them. bgpWatcher := ygnmi.Watch( diff --git a/bgp/ocgobgp.go b/bgp/ocgobgp.go index a0fc5c85..45c6442e 100644 --- a/bgp/ocgobgp.go +++ b/bgp/ocgobgp.go @@ -24,7 +24,7 @@ import ( log "github.com/golang/glog" "github.com/openconfig/lemming/gnmi/oc" - "github.com/wenovus/gobgp/v3/pkg/config/gobgp" + gobgpoc "github.com/wenovus/gobgp/v3/pkg/config/oc" ) // convertPolicyName converts from OC policy name to a neighbour-qualified @@ -33,7 +33,7 @@ func convertPolicyName(neighAddr, ocPolicyName string) string { return neighAddr + "|" + ocPolicyName } -func convertSetCommunities(setCommunity *oc.RoutingPolicy_PolicyDefinition_Statement_Actions_BgpActions_SetCommunity, convertedCommSets []gobgp.CommunitySet, commSetIndexMap map[string]int) ([]string, error) { +func convertSetCommunities(setCommunity *oc.RoutingPolicy_PolicyDefinition_Statement_Actions_BgpActions_SetCommunity, convertedCommSets []gobgpoc.CommunitySet, commSetIndexMap map[string]int) ([]string, error) { switch setCommunity.GetMethod() { case oc.SetCommunity_Method_INLINE: var setCommunitiesList []string @@ -59,9 +59,9 @@ func convertSetCommunities(setCommunity *oc.RoutingPolicy_PolicyDefinition_State // It adds neighbour set to disambiguate it from another instance of the policy // for another neighbour. This is necessary since all policies will go into a // single apply-policy list. -func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAddr string, occommset map[string]*oc.RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySet, convertedCommSets []gobgp.CommunitySet, commSetIndexMap map[string]int) gobgp.PolicyDefinition { +func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAddr string, occommset map[string]*oc.RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySet, convertedCommSets []gobgpoc.CommunitySet, commSetIndexMap map[string]int) gobgpoc.PolicyDefinition { convertedPolicyName := convertPolicyName(neighAddr, policy.GetName()) - var statements []gobgp.Statement + var statements []gobgpoc.Statement for _, statement := range policy.Statement.Values() { setCommunitiesList, err := convertSetCommunities(statement.GetActions().GetBgpActions().GetSetCommunity(), convertedCommSets, commSetIndexMap) if err != nil { @@ -71,42 +71,42 @@ func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAdd if err != nil { log.Errorf("MED value not supported: %v", err) } - statements = append(statements, gobgp.Statement{ + statements = append(statements, gobgpoc.Statement{ // In GoBGP, statements must have globally-unique names. // Ensure uniqueness by qualifying each one with the name of the converted policy. Name: convertedPolicyName + ":" + statement.GetName(), - Conditions: gobgp.Conditions{ - MatchPrefixSet: gobgp.MatchPrefixSet{ + Conditions: gobgpoc.Conditions{ + MatchPrefixSet: gobgpoc.MatchPrefixSet{ PrefixSet: statement.GetConditions().GetMatchPrefixSet().GetPrefixSet(), MatchSetOptions: convertMatchSetOptionsRestrictedType(statement.GetConditions().GetMatchPrefixSet().GetMatchSetOptions()), }, - MatchNeighborSet: gobgp.MatchNeighborSet{ + MatchNeighborSet: gobgpoc.MatchNeighborSet{ // Name the neighbor set as the policy so that the policy only applies to referring neighbours. NeighborSet: neighAddr, }, - BgpConditions: gobgp.BgpConditions{ - MatchCommunitySet: gobgp.MatchCommunitySet{ + BgpConditions: gobgpoc.BgpConditions{ + MatchCommunitySet: gobgpoc.MatchCommunitySet{ CommunitySet: statement.Conditions.GetBgpConditions().GetCommunitySet(), MatchSetOptions: convertMatchSetOptionsType(occommset[statement.GetConditions().GetBgpConditions().GetCommunitySet()].GetMatchSetOptions()), }, - MatchAsPathSet: gobgp.MatchAsPathSet{ + MatchAsPathSet: gobgpoc.MatchAsPathSet{ AsPathSet: statement.Conditions.GetBgpConditions().GetMatchAsPathSet().GetAsPathSet(), MatchSetOptions: convertMatchSetOptionsType(statement.GetConditions().GetBgpConditions().GetMatchAsPathSet().GetMatchSetOptions()), }, }, }, - Actions: gobgp.Actions{ + Actions: gobgpoc.Actions{ RouteDisposition: convertRouteDisposition(statement.GetActions().GetPolicyResult()), - BgpActions: gobgp.BgpActions{ - SetCommunity: gobgp.SetCommunity{ - SetCommunityMethod: gobgp.SetCommunityMethod{ + BgpActions: gobgpoc.BgpActions{ + SetCommunity: gobgpoc.SetCommunity{ + SetCommunityMethod: gobgpoc.SetCommunityMethod{ CommunitiesList: setCommunitiesList, }, Options: strings.ToLower(statement.GetActions().GetBgpActions().GetSetCommunity().GetOptions().String()), }, SetLocalPref: statement.GetActions().GetBgpActions().GetSetLocalPref(), - SetMed: gobgp.BgpSetMedType(setmed), - SetAsPathPrepend: gobgp.SetAsPathPrepend{ + SetMed: gobgpoc.BgpSetMedType(setmed), + SetAsPathPrepend: gobgpoc.SetAsPathPrepend{ RepeatN: statement.GetActions().GetBgpActions().GetSetAsPathPrepend().GetRepeatN(), As: strconv.FormatUint(uint64(statement.GetActions().GetBgpActions().GetSetAsPathPrepend().GetAsn()), 10), }, @@ -115,15 +115,15 @@ func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAdd }) } - return gobgp.PolicyDefinition{ + return gobgpoc.PolicyDefinition{ Name: convertedPolicyName, Statements: statements, } } -func convertNeighborApplyPolicy(neigh *oc.NetworkInstance_Protocol_Bgp_Neighbor) gobgp.ApplyPolicy { - return gobgp.ApplyPolicy{ - Config: gobgp.ApplyPolicyConfig{ +func convertNeighborApplyPolicy(neigh *oc.NetworkInstance_Protocol_Bgp_Neighbor) gobgpoc.ApplyPolicy { + return gobgpoc.ApplyPolicy{ + Config: gobgpoc.ApplyPolicyConfig{ DefaultImportPolicy: convertDefaultPolicy(neigh.GetApplyPolicy().GetDefaultImportPolicy()), DefaultExportPolicy: convertDefaultPolicy(neigh.GetApplyPolicy().GetDefaultExportPolicy()), ImportPolicyList: neigh.GetApplyPolicy().GetImportPolicy(), @@ -134,60 +134,60 @@ func convertNeighborApplyPolicy(neigh *oc.NetworkInstance_Protocol_Bgp_Neighbor) // TODO(wenbli): Add unit tests for these conversion functions. -func convertDefaultPolicy(ocpolicy oc.E_RoutingPolicy_DefaultPolicyType) gobgp.DefaultPolicyType { +func convertDefaultPolicy(ocpolicy oc.E_RoutingPolicy_DefaultPolicyType) gobgpoc.DefaultPolicyType { switch ocpolicy { case oc.RoutingPolicy_DefaultPolicyType_REJECT_ROUTE: - return gobgp.DEFAULT_POLICY_TYPE_REJECT_ROUTE + return gobgpoc.DEFAULT_POLICY_TYPE_REJECT_ROUTE case oc.RoutingPolicy_DefaultPolicyType_ACCEPT_ROUTE: - return gobgp.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE + return gobgpoc.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE default: - return gobgp.DEFAULT_POLICY_TYPE_REJECT_ROUTE + return gobgpoc.DEFAULT_POLICY_TYPE_REJECT_ROUTE } } -func convertMatchSetOptionsType(ocMatchSetOpts oc.E_RoutingPolicy_MatchSetOptionsType) gobgp.MatchSetOptionsType { +func convertMatchSetOptionsType(ocMatchSetOpts oc.E_RoutingPolicy_MatchSetOptionsType) gobgpoc.MatchSetOptionsType { switch ocMatchSetOpts { case oc.RoutingPolicy_MatchSetOptionsType_INVERT: - return gobgp.MATCH_SET_OPTIONS_TYPE_INVERT + return gobgpoc.MATCH_SET_OPTIONS_TYPE_INVERT case oc.RoutingPolicy_MatchSetOptionsType_ANY: - return gobgp.MATCH_SET_OPTIONS_TYPE_ANY + return gobgpoc.MATCH_SET_OPTIONS_TYPE_ANY case oc.RoutingPolicy_MatchSetOptionsType_ALL: - return gobgp.MATCH_SET_OPTIONS_TYPE_ALL + return gobgpoc.MATCH_SET_OPTIONS_TYPE_ALL default: - return gobgp.MATCH_SET_OPTIONS_TYPE_ANY + return gobgpoc.MATCH_SET_OPTIONS_TYPE_ANY } } -func convertMatchSetOptionsRestrictedType(ocrestrictedMatchSetOpts oc.E_RoutingPolicy_MatchSetOptionsRestrictedType) gobgp.MatchSetOptionsRestrictedType { +func convertMatchSetOptionsRestrictedType(ocrestrictedMatchSetOpts oc.E_RoutingPolicy_MatchSetOptionsRestrictedType) gobgpoc.MatchSetOptionsRestrictedType { switch ocrestrictedMatchSetOpts { case oc.RoutingPolicy_MatchSetOptionsRestrictedType_INVERT: - return gobgp.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT + return gobgpoc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT case oc.RoutingPolicy_MatchSetOptionsRestrictedType_ANY: - return gobgp.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + return gobgpoc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY default: - return gobgp.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + return gobgpoc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY } } -func convertRouteDisposition(ocpolicyresult oc.E_RoutingPolicy_PolicyResultType) gobgp.RouteDisposition { +func convertRouteDisposition(ocpolicyresult oc.E_RoutingPolicy_PolicyResultType) gobgpoc.RouteDisposition { switch ocpolicyresult { case oc.RoutingPolicy_PolicyResultType_REJECT_ROUTE: - return gobgp.ROUTE_DISPOSITION_REJECT_ROUTE + return gobgpoc.ROUTE_DISPOSITION_REJECT_ROUTE case oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE: - return gobgp.ROUTE_DISPOSITION_ACCEPT_ROUTE + return gobgpoc.ROUTE_DISPOSITION_ACCEPT_ROUTE default: - return gobgp.ROUTE_DISPOSITION_NONE + return gobgpoc.ROUTE_DISPOSITION_NONE } } -func defaultPolicyToRouteDisp(gobgpdefaultpolicy gobgp.DefaultPolicyType) gobgp.RouteDisposition { +func defaultPolicyToRouteDisp(gobgpdefaultpolicy gobgpoc.DefaultPolicyType) gobgpoc.RouteDisposition { switch gobgpdefaultpolicy { - case gobgp.DEFAULT_POLICY_TYPE_REJECT_ROUTE: - return gobgp.ROUTE_DISPOSITION_REJECT_ROUTE - case gobgp.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE: - return gobgp.ROUTE_DISPOSITION_ACCEPT_ROUTE + case gobgpoc.DEFAULT_POLICY_TYPE_REJECT_ROUTE: + return gobgpoc.ROUTE_DISPOSITION_REJECT_ROUTE + case gobgpoc.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE: + return gobgpoc.ROUTE_DISPOSITION_ACCEPT_ROUTE default: - return gobgp.ROUTE_DISPOSITION_REJECT_ROUTE + return gobgpoc.ROUTE_DISPOSITION_REJECT_ROUTE } } @@ -213,9 +213,9 @@ func convertCommunity(community any) string { return "" } -func convertCommunitySet(occommset map[string]*oc.RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySet) ([]gobgp.CommunitySet, map[string]int) { +func convertCommunitySet(occommset map[string]*oc.RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySet) ([]gobgpoc.CommunitySet, map[string]int) { indexMap := map[string]int{} - var commsets []gobgp.CommunitySet + var commsets []gobgpoc.CommunitySet commNames := maps.Keys(occommset) slices.Sort(commNames) for _, communitySetName := range commNames { @@ -225,7 +225,7 @@ func convertCommunitySet(occommset map[string]*oc.RoutingPolicy_DefinedSets_BgpD } indexMap[communitySetName] = len(commsets) - commsets = append(commsets, gobgp.CommunitySet{ + commsets = append(commsets, gobgpoc.CommunitySet{ CommunitySetName: communitySetName, CommunityList: communityList, }) @@ -250,25 +250,25 @@ func communitiesToOC(communities []uint32) []oc.NetworkInstance_Protocol_Bgp_Rib return occomms } -func convertPrefixSets(ocprefixsets map[string]*oc.RoutingPolicy_DefinedSets_PrefixSet) []gobgp.PrefixSet { - var prefixSets []gobgp.PrefixSet +func convertPrefixSets(ocprefixsets map[string]*oc.RoutingPolicy_DefinedSets_PrefixSet) []gobgpoc.PrefixSet { + var prefixSets []gobgpoc.PrefixSet prefixSetNames := maps.Keys(ocprefixsets) slices.Sort(prefixSetNames) for _, prefixSetName := range prefixSetNames { - var prefixList []gobgp.Prefix + var prefixList []gobgpoc.Prefix for _, prefix := range ocprefixsets[prefixSetName].Prefix { r := prefix.GetMasklengthRange() if r == "exact" { // GoBGP recognizes "" instead of "exact" r = "" } - prefixList = append(prefixList, gobgp.Prefix{ + prefixList = append(prefixList, gobgpoc.Prefix{ IpPrefix: prefix.GetIpPrefix(), MasklengthRange: r, }) } - prefixSets = append(prefixSets, gobgp.PrefixSet{ + prefixSets = append(prefixSets, gobgpoc.PrefixSet{ PrefixSetName: prefixSetName, PrefixList: prefixList, }) @@ -276,10 +276,10 @@ func convertPrefixSets(ocprefixsets map[string]*oc.RoutingPolicy_DefinedSets_Pre return prefixSets } -func convertASPathSets(ocpathset map[string]*oc.RoutingPolicy_DefinedSets_BgpDefinedSets_AsPathSet) []gobgp.AsPathSet { - var pathsets []gobgp.AsPathSet +func convertASPathSets(ocpathset map[string]*oc.RoutingPolicy_DefinedSets_BgpDefinedSets_AsPathSet) []gobgpoc.AsPathSet { + var pathsets []gobgpoc.AsPathSet for pathsetName, pathset := range ocpathset { - pathsets = append(pathsets, gobgp.AsPathSet{ + pathsets = append(pathsets, gobgpoc.AsPathSet{ AsPathSetName: pathsetName, AsPathList: pathset.AsPathSetMember, }) diff --git a/go.mod b/go.mod index 7b4a1bb9..4e5156d2 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/spf13/viper v1.16.0 github.com/stoewer/go-strcase v1.3.0 github.com/vishvananda/netlink v1.2.1-beta.2 - github.com/wenovus/gobgp/v3 v3.0.0-20230919213724-0f6fb3b45ead + github.com/wenovus/gobgp/v3 v3.0.0-20231024172553-6f8061a337a8 go.uber.org/mock v0.2.0 golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b golang.org/x/sys v0.13.0 diff --git a/go.sum b/go.sum index 4d017764..13b6c63b 100644 --- a/go.sum +++ b/go.sum @@ -1066,8 +1066,8 @@ github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhg github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= -github.com/wenovus/gobgp/v3 v3.0.0-20230919213724-0f6fb3b45ead h1:CTaAeRUMWmcr/m8nyRq9wx5+SFO+ymR9V4Dv1ZpFZV0= -github.com/wenovus/gobgp/v3 v3.0.0-20230919213724-0f6fb3b45ead/go.mod h1:eWnDOKq8YXjzWTL4l8ZwUt3wLqTsb0Cb+mVfUbLMvgU= +github.com/wenovus/gobgp/v3 v3.0.0-20231024172553-6f8061a337a8 h1:Cy3PTEuyD9zcf2Fav9SphOOkrEYXIhhzKpuRWfbLVvo= +github.com/wenovus/gobgp/v3 v3.0.0-20231024172553-6f8061a337a8/go.mod h1:ITr0lebPaiW89whkrVfHAkamLmJ2MNElKzoFN+I4fUA= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/repositories.bzl b/repositories.bzl index 71b2a3c8..0152f573 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -2026,8 +2026,8 @@ def go_repositories(): name = "com_github_wenovus_gobgp_v3", build_file_proto_mode = "disable", importpath = "github.com/wenovus/gobgp/v3", - sum = "h1:CTaAeRUMWmcr/m8nyRq9wx5+SFO+ymR9V4Dv1ZpFZV0=", - version = "v3.0.0-20230919213724-0f6fb3b45ead", + sum = "h1:Cy3PTEuyD9zcf2Fav9SphOOkrEYXIhhzKpuRWfbLVvo=", + version = "v3.0.0-20231024172553-6f8061a337a8", ) go_repository( name = "com_github_xanzy_ssh_agent",