diff options
-rw-r--r-- | cmd/gobgpd/main.go | 4 | ||||
-rw-r--r-- | internal/pkg/config/util.go | 75 | ||||
-rw-r--r-- | internal/pkg/table/policy.go | 16 | ||||
-rw-r--r-- | pkg/server/grpc_server.go | 91 |
4 files changed, 93 insertions, 93 deletions
diff --git a/cmd/gobgpd/main.go b/cmd/gobgpd/main.go index b87c478d..23e7ec96 100644 --- a/cmd/gobgpd/main.go +++ b/cmd/gobgpd/main.go @@ -269,7 +269,7 @@ func main() { } } p := config.ConfigSetToRoutingPolicy(newConfig) - rp, err := server.NewAPIRoutingPolicyFromConfigStruct(p) + rp, err := table.NewAPIRoutingPolicyFromConfigStruct(p) if err != nil { log.Warn(err) } else { @@ -297,7 +297,7 @@ func main() { if updatePolicy { log.Info("Policy config is updated") p := config.ConfigSetToRoutingPolicy(newConfig) - rp, err := server.NewAPIRoutingPolicyFromConfigStruct(p) + rp, err := table.NewAPIRoutingPolicyFromConfigStruct(p) if err != nil { log.Warn(err) } else { diff --git a/internal/pkg/config/util.go b/internal/pkg/config/util.go index 47c7d37f..ed9d3049 100644 --- a/internal/pkg/config/util.go +++ b/internal/pkg/config/util.go @@ -642,3 +642,78 @@ func NewGlobalFromConfigStruct(c *Global) *api.Global { ApplyPolicy: applyPolicy, } } + +func newAPIPrefixFromConfigStruct(c Prefix) (*api.Prefix, error) { + min, max, err := ParseMaskLength(c.IpPrefix, c.MasklengthRange) + if err != nil { + return nil, err + } + return &api.Prefix{ + IpPrefix: c.IpPrefix, + MaskLengthMin: uint32(min), + MaskLengthMax: uint32(max), + }, nil +} + +func NewAPIDefinedSetsFromConfigStruct(t *DefinedSets) ([]*api.DefinedSet, error) { + definedSets := make([]*api.DefinedSet, 0) + + for _, ps := range t.PrefixSets { + prefixes := make([]*api.Prefix, 0) + for _, p := range ps.PrefixList { + ap, err := newAPIPrefixFromConfigStruct(p) + if err != nil { + return nil, err + } + prefixes = append(prefixes, ap) + } + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_PREFIX, + Name: ps.PrefixSetName, + Prefixes: prefixes, + }) + } + + for _, ns := range t.NeighborSets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_NEIGHBOR, + Name: ns.NeighborSetName, + List: ns.NeighborInfoList, + }) + } + + bs := t.BgpDefinedSets + for _, cs := range bs.CommunitySets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_COMMUNITY, + Name: cs.CommunitySetName, + List: cs.CommunityList, + }) + } + + for _, es := range bs.ExtCommunitySets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_EXT_COMMUNITY, + Name: es.ExtCommunitySetName, + List: es.ExtCommunityList, + }) + } + + for _, ls := range bs.LargeCommunitySets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_LARGE_COMMUNITY, + Name: ls.LargeCommunitySetName, + List: ls.LargeCommunityList, + }) + } + + for _, as := range bs.AsPathSets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_AS_PATH, + Name: as.AsPathSetName, + List: as.AsPathList, + }) + } + + return definedSets, nil +} diff --git a/internal/pkg/table/policy.go b/internal/pkg/table/policy.go index b06da47d..73bfac75 100644 --- a/internal/pkg/table/policy.go +++ b/internal/pkg/table/policy.go @@ -4117,3 +4117,19 @@ func NewAPIPolicyAssignmentFromTableStruct(t *PolicyAssignment) *api.PolicyAssig }(), } } + +func NewAPIRoutingPolicyFromConfigStruct(c *config.RoutingPolicy) (*api.RoutingPolicy, error) { + definedSets, err := config.NewAPIDefinedSetsFromConfigStruct(&c.DefinedSets) + if err != nil { + return nil, err + } + policies := make([]*api.Policy, 0, len(c.PolicyDefinitions)) + for _, policy := range c.PolicyDefinitions { + policies = append(policies, ToPolicyApi(&policy)) + } + + return &api.RoutingPolicy{ + DefinedSets: definedSets, + Policies: policies, + }, nil +} diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 9ecc6250..9f6b5bbb 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -297,22 +297,6 @@ func (s *Server) SetPolicies(ctx context.Context, r *api.SetPoliciesRequest) (*e return &empty.Empty{}, s.bgpServer.SetPolicies(ctx, r) } -func NewAPIRoutingPolicyFromConfigStruct(c *config.RoutingPolicy) (*api.RoutingPolicy, error) { - definedSets, err := newAPIDefinedSetsFromConfigStruct(&c.DefinedSets) - if err != nil { - return nil, err - } - policies := make([]*api.Policy, 0, len(c.PolicyDefinitions)) - for _, policy := range c.PolicyDefinitions { - policies = append(policies, table.ToPolicyApi(&policy)) - } - - return &api.RoutingPolicy{ - DefinedSets: definedSets, - Policies: policies, - }, nil -} - func NewRoutingPolicyFromApiStruct(arg *api.SetPoliciesRequest) (*config.RoutingPolicy, error) { policyDefinitions := make([]config.PolicyDefinition, 0, len(arg.Policies)) for _, p := range arg.Policies { @@ -937,81 +921,6 @@ func newConfigPrefixFromAPIStruct(a *api.Prefix) (*config.Prefix, error) { }, nil } -func newAPIPrefixFromConfigStruct(c config.Prefix) (*api.Prefix, error) { - min, max, err := config.ParseMaskLength(c.IpPrefix, c.MasklengthRange) - if err != nil { - return nil, err - } - return &api.Prefix{ - IpPrefix: c.IpPrefix, - MaskLengthMin: uint32(min), - MaskLengthMax: uint32(max), - }, nil -} - -func newAPIDefinedSetsFromConfigStruct(t *config.DefinedSets) ([]*api.DefinedSet, error) { - definedSets := make([]*api.DefinedSet, 0) - - for _, ps := range t.PrefixSets { - prefixes := make([]*api.Prefix, 0) - for _, p := range ps.PrefixList { - ap, err := newAPIPrefixFromConfigStruct(p) - if err != nil { - return nil, err - } - prefixes = append(prefixes, ap) - } - definedSets = append(definedSets, &api.DefinedSet{ - Type: api.DefinedType_PREFIX, - Name: ps.PrefixSetName, - Prefixes: prefixes, - }) - } - - for _, ns := range t.NeighborSets { - definedSets = append(definedSets, &api.DefinedSet{ - Type: api.DefinedType_NEIGHBOR, - Name: ns.NeighborSetName, - List: ns.NeighborInfoList, - }) - } - - bs := t.BgpDefinedSets - for _, cs := range bs.CommunitySets { - definedSets = append(definedSets, &api.DefinedSet{ - Type: api.DefinedType_COMMUNITY, - Name: cs.CommunitySetName, - List: cs.CommunityList, - }) - } - - for _, es := range bs.ExtCommunitySets { - definedSets = append(definedSets, &api.DefinedSet{ - Type: api.DefinedType_EXT_COMMUNITY, - Name: es.ExtCommunitySetName, - List: es.ExtCommunityList, - }) - } - - for _, ls := range bs.LargeCommunitySets { - definedSets = append(definedSets, &api.DefinedSet{ - Type: api.DefinedType_LARGE_COMMUNITY, - Name: ls.LargeCommunitySetName, - List: ls.LargeCommunityList, - }) - } - - for _, as := range bs.AsPathSets { - definedSets = append(definedSets, &api.DefinedSet{ - Type: api.DefinedType_AS_PATH, - Name: as.AsPathSetName, - List: as.AsPathList, - }) - } - - return definedSets, nil -} - func newConfigDefinedSetsFromApiStruct(a []*api.DefinedSet) (*config.DefinedSets, error) { ps := make([]config.PrefixSet, 0) ns := make([]config.NeighborSet, 0) |