diff --git a/cmd/gobgp/neighbor.go b/cmd/gobgp/neighbor.go index 80e6291d3..f4417c637 100644 --- a/cmd/gobgp/neighbor.go +++ b/cmd/gobgp/neighbor.go @@ -31,8 +31,8 @@ import ( "golang.org/x/text/language" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/pkg/apiutil" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -1283,7 +1283,7 @@ func modNeighbor(cmdType string, args []string) error { getNeighborAddress := func() (string, error) { if unnumbered { - return config.GetIPv6LinkLocalNeighborAddress(m["interface"][0]) + return oc.GetIPv6LinkLocalNeighborAddress(m["interface"][0]) } return m[""][0], nil } diff --git a/cmd/gobgp/policy.go b/cmd/gobgp/policy.go index 5eab6a344..8f2564329 100644 --- a/cmd/gobgp/policy.go +++ b/cmd/gobgp/policy.go @@ -28,9 +28,9 @@ import ( "github.com/spf13/cobra" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" "github.com/osrg/gobgp/v3/pkg/apiutil" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -251,7 +251,7 @@ func parsePrefixSet(args []string) (*api.DefinedSet, error) { if len(args) > 1 { mask = args[1] } - min, max, err := config.ParseMaskLength(args[0], mask) + min, max, err := oc.ParseMaskLength(args[0], mask) if err != nil { return nil, err } @@ -779,11 +779,11 @@ func modCondition(name, op string, args []string) error { } switch strings.ToLower(args[0]) { case "valid": - stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_VALID]) + stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_VALID]) case "invalid": - stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_INVALID]) + stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_INVALID]) case "not-found": - stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND]) + stmt.Conditions.RpkiResult = int32(oc.RpkiValidationResultTypeToIntMap[oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND]) default: return fmt.Errorf("%s rpki { valid | invalid | not-found }", usage) } diff --git a/internal/pkg/table/destination.go b/internal/pkg/table/destination.go index d5b6bcd21..c75332848 100644 --- a/internal/pkg/table/destination.go +++ b/internal/pkg/table/destination.go @@ -23,13 +23,13 @@ import ( "net" "sort" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) -var SelectionOptions config.RouteSelectionOptionsConfig -var UseMultiplePaths config.UseMultiplePathsConfig +var SelectionOptions oc.RouteSelectionOptionsConfig +var UseMultiplePaths oc.UseMultiplePathsConfig type BestPathReason uint8 @@ -118,7 +118,7 @@ func (i *PeerInfo) String() string { return s.String() } -func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo { +func NewPeerInfo(g *oc.Global, p *oc.Neighbor) *PeerInfo { clusterID := net.ParseIP(string(p.RouteReflector.State.RouteReflectorClusterId)).To4() // exclude zone info naddr, _ := net.ResolveIPAddr("ip", p.State.NeighborAddress) diff --git a/internal/pkg/table/path.go b/internal/pkg/table/path.go index c718d0557..06da04dca 100644 --- a/internal/pkg/table/path.go +++ b/internal/pkg/table/path.go @@ -24,7 +24,7 @@ import ( "sort" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -121,7 +121,7 @@ var IntToRpkiValidationReasonTypeMap = map[int]RpkiValidationReasonType{ } type Validation struct { - Status config.RpkiValidationResultType + Status oc.RpkiValidationResultType Reason RpkiValidationReasonType Matched []*ROA UnmatchedAs []*ROA @@ -194,7 +194,7 @@ func cloneAsPath(asAttr *bgp.PathAttributeAsPath) *bgp.PathAttributeAsPath { return bgp.NewPathAttributeAsPath(newASparams) } -func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neighbor, info *PeerInfo, original *Path) *Path { +func UpdatePathAttrs(logger log.Logger, global *oc.Global, peer *oc.Neighbor, info *PeerInfo, original *Path) *Path { if peer.RouteServer.Config.RouteServerClient { return original } @@ -208,7 +208,7 @@ func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neig } else { switch a.GetType() { case bgp.BGP_ATTR_TYPE_CLUSTER_LIST, bgp.BGP_ATTR_TYPE_ORIGINATOR_ID: - if !(peer.State.PeerType == config.PEER_TYPE_INTERNAL && peer.RouteReflector.Config.RouteReflectorClient) { + if !(peer.State.PeerType == oc.PEER_TYPE_INTERNAL && peer.RouteReflector.Config.RouteReflectorClient) { // send these attributes to only rr clients path.delPathAttr(a.GetType()) } @@ -218,7 +218,7 @@ func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neig localAddress := info.LocalAddress nexthop := path.GetNexthop() - if peer.State.PeerType == config.PEER_TYPE_EXTERNAL { + if peer.State.PeerType == oc.PEER_TYPE_EXTERNAL { // NEXTHOP handling if !path.IsLocal() || nexthop.IsUnspecified() { path.SetNexthop(localAddress) @@ -239,7 +239,7 @@ func UpdatePathAttrs(logger log.Logger, global *config.Global, peer *config.Neig path.delPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) } - } else if peer.State.PeerType == config.PEER_TYPE_INTERNAL { + } else if peer.State.PeerType == oc.PEER_TYPE_INTERNAL { // NEXTHOP handling for iBGP // if the path generated locally set local address as nexthop. // if not, don't modify it. @@ -713,20 +713,20 @@ func isPrivateAS(as uint32) bool { return (64512 <= as && as <= 65534) || (4200000000 <= as && as <= 4294967294) } -func (path *Path) RemovePrivateAS(localAS uint32, option config.RemovePrivateAsOption) { +func (path *Path) RemovePrivateAS(localAS uint32, option oc.RemovePrivateAsOption) { original := path.GetAsPath() if original == nil { return } switch option { - case config.REMOVE_PRIVATE_AS_OPTION_ALL, config.REMOVE_PRIVATE_AS_OPTION_REPLACE: + case oc.REMOVE_PRIVATE_AS_OPTION_ALL, oc.REMOVE_PRIVATE_AS_OPTION_REPLACE: newASParams := make([]bgp.AsPathParamInterface, 0, len(original.Value)) for _, param := range original.Value { asList := param.GetAS() newASParam := make([]uint32, 0, len(asList)) for _, as := range asList { if isPrivateAS(as) { - if option == config.REMOVE_PRIVATE_AS_OPTION_REPLACE { + if option == oc.REMOVE_PRIVATE_AS_OPTION_REPLACE { newASParam = append(newASParam, localAS) } } else { diff --git a/internal/pkg/table/path_test.go b/internal/pkg/table/path_test.go index 172b17e3c..58ef1836c 100644 --- a/internal/pkg/table/path_test.go +++ b/internal/pkg/table/path_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/stretchr/testify/assert" @@ -335,14 +335,14 @@ func TestRemovePrivateAS(t *testing.T) { aspath := bgp.NewPathAttributeAsPath(aspathParam) nlri := bgp.NewIPAddrPrefix(24, "30.30.30.0") path := NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false) - path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_ALL) + path.RemovePrivateAS(10, oc.REMOVE_PRIVATE_AS_OPTION_ALL) list := path.GetAsList() assert.Equal(t, len(list), 2) assert.Equal(t, list[0], uint32(1)) assert.Equal(t, list[1], uint32(2)) path = NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false) - path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_REPLACE) + path.RemovePrivateAS(10, oc.REMOVE_PRIVATE_AS_OPTION_REPLACE) list = path.GetAsList() assert.Equal(t, len(list), 4) assert.Equal(t, list[0], uint32(10)) diff --git a/internal/pkg/table/policy.go b/internal/pkg/table/policy.go index d22b1ad95..50b81da92 100644 --- a/internal/pkg/table/policy.go +++ b/internal/pkg/table/policy.go @@ -28,7 +28,7 @@ import ( "github.com/k-sone/critbitgo" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -111,12 +111,12 @@ func (o MatchOption) String() string { } } -func (o MatchOption) ConvertToMatchSetOptionsRestrictedType() config.MatchSetOptionsRestrictedType { +func (o MatchOption) ConvertToMatchSetOptionsRestrictedType() oc.MatchSetOptionsRestrictedType { switch o { case MATCH_OPTION_ANY: - return config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + return oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY case MATCH_OPTION_INVERT: - return config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT + return oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT } return "unknown" } @@ -128,16 +128,16 @@ const ( MED_ACTION_REPLACE ) -var CommunityOptionNameMap = map[config.BgpSetCommunityOptionType]string{ - config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: "add", - config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: "remove", - config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: "replace", +var CommunityOptionNameMap = map[oc.BgpSetCommunityOptionType]string{ + oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: "add", + oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: "remove", + oc.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: "replace", } -var CommunityOptionValueMap = map[string]config.BgpSetCommunityOptionType{ - CommunityOptionNameMap[config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD]: config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD, - CommunityOptionNameMap[config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE]: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, - CommunityOptionNameMap[config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE]: config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE, +var CommunityOptionValueMap = map[string]oc.BgpSetCommunityOptionType{ + CommunityOptionNameMap[oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD]: oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD, + CommunityOptionNameMap[oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE]: oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + CommunityOptionNameMap[oc.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE]: oc.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE, } type ConditionType int @@ -171,22 +171,22 @@ const ( func NewMatchOption(c interface{}) (MatchOption, error) { switch t := c.(type) { - case config.MatchSetOptionsType: + case oc.MatchSetOptionsType: t = t.DefaultAsNeeded() switch t { - case config.MATCH_SET_OPTIONS_TYPE_ANY: + case oc.MATCH_SET_OPTIONS_TYPE_ANY: return MATCH_OPTION_ANY, nil - case config.MATCH_SET_OPTIONS_TYPE_ALL: + case oc.MATCH_SET_OPTIONS_TYPE_ALL: return MATCH_OPTION_ALL, nil - case config.MATCH_SET_OPTIONS_TYPE_INVERT: + case oc.MATCH_SET_OPTIONS_TYPE_INVERT: return MATCH_OPTION_INVERT, nil } - case config.MatchSetOptionsRestrictedType: + case oc.MatchSetOptionsRestrictedType: t = t.DefaultAsNeeded() switch t { - case config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY: + case oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY: return MATCH_OPTION_ANY, nil - case config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT: + case oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT: return MATCH_OPTION_INVERT, nil } } @@ -308,7 +308,7 @@ func (p *Prefix) PrefixString() string { var _regexpPrefixRange = regexp.MustCompile(`(\d+)\.\.(\d+)`) -func NewPrefix(c config.Prefix) (*Prefix, error) { +func NewPrefix(c oc.Prefix) (*Prefix, error) { _, prefix, err := net.ParseCIDR(c.IpPrefix) if err != nil { return nil, err @@ -443,16 +443,16 @@ func (s *PrefixSet) List() []string { return list } -func (s *PrefixSet) ToConfig() *config.PrefixSet { - list := make([]config.Prefix, 0, s.tree.Size()) +func (s *PrefixSet) ToConfig() *oc.PrefixSet { + list := make([]oc.Prefix, 0, s.tree.Size()) s.tree.Walk(nil, func(_ *net.IPNet, v interface{}) bool { ps := v.([]*Prefix) for _, p := range ps { - list = append(list, config.Prefix{IpPrefix: p.PrefixString(), MasklengthRange: fmt.Sprintf("%d..%d", p.MasklengthRangeMin, p.MasklengthRangeMax)}) + list = append(list, oc.Prefix{IpPrefix: p.PrefixString(), MasklengthRange: fmt.Sprintf("%d..%d", p.MasklengthRangeMin, p.MasklengthRangeMax)}) } return true }) - return &config.PrefixSet{ + return &oc.PrefixSet{ PrefixSetName: s.name, PrefixList: list, } @@ -493,7 +493,7 @@ func NewPrefixSetFromApiStruct(name string, prefixes []*Prefix) (*PrefixSet, err }, nil } -func NewPrefixSet(c config.PrefixSet) (*PrefixSet, error) { +func NewPrefixSet(c oc.PrefixSet) (*PrefixSet, error) { name := c.PrefixSetName if name == "" { if len(c.PrefixList) == 0 { @@ -692,8 +692,8 @@ func (s *NeighborSet) List() []string { return list } -func (s *NeighborSet) ToConfig() *config.NeighborSet { - return &config.NeighborSet{ +func (s *NeighborSet) ToConfig() *oc.NeighborSet { + return &oc.NeighborSet{ NeighborSetName: s.name, NeighborInfoList: s.List(), } @@ -714,7 +714,7 @@ func NewNeighborSetFromApiStruct(name string, list []net.IPNet) (*NeighborSet, e }, nil } -func NewNeighborSet(c config.NeighborSet) (*NeighborSet, error) { +func NewNeighborSet(c oc.NeighborSet) (*NeighborSet, error) { name := c.NeighborSetName if name == "" { if len(c.NeighborInfoList) == 0 { @@ -923,8 +923,8 @@ func (s *AsPathSet) List() []string { return list } -func (s *AsPathSet) ToConfig() *config.AsPathSet { - return &config.AsPathSet{ +func (s *AsPathSet) ToConfig() *oc.AsPathSet { + return &oc.AsPathSet{ AsPathSetName: s.name, AsPathList: s.List(), } @@ -938,7 +938,7 @@ func (s *AsPathSet) MarshalJSON() ([]byte, error) { return json.Marshal(s.ToConfig()) } -func NewAsPathSet(c config.AsPathSet) (*AsPathSet, error) { +func NewAsPathSet(c oc.AsPathSet) (*AsPathSet, error) { name := c.AsPathSetName if name == "" { if len(c.AsPathList) == 0 { @@ -1062,8 +1062,8 @@ func (s *CommunitySet) List() []string { return list } -func (s *CommunitySet) ToConfig() *config.CommunitySet { - return &config.CommunitySet{ +func (s *CommunitySet) ToConfig() *oc.CommunitySet { + return &oc.CommunitySet{ CommunitySetName: s.name, CommunityList: s.List(), } @@ -1177,7 +1177,7 @@ func ParseExtCommunityRegexp(arg string) (bgp.ExtendedCommunityAttrSubType, *reg return subtype, exp, err } -func NewCommunitySet(c config.CommunitySet) (*CommunitySet, error) { +func NewCommunitySet(c oc.CommunitySet) (*CommunitySet, error) { name := c.CommunitySetName if name == "" { if len(c.CommunityList) == 0 { @@ -1231,8 +1231,8 @@ func (s *ExtCommunitySet) List() []string { return list } -func (s *ExtCommunitySet) ToConfig() *config.ExtCommunitySet { - return &config.ExtCommunitySet{ +func (s *ExtCommunitySet) ToConfig() *oc.ExtCommunitySet { + return &oc.ExtCommunitySet{ ExtCommunitySetName: s.name, ExtCommunityList: s.List(), } @@ -1246,7 +1246,7 @@ func (s *ExtCommunitySet) MarshalJSON() ([]byte, error) { return json.Marshal(s.ToConfig()) } -func NewExtCommunitySet(c config.ExtCommunitySet) (*ExtCommunitySet, error) { +func NewExtCommunitySet(c oc.ExtCommunitySet) (*ExtCommunitySet, error) { name := c.ExtCommunitySetName if name == "" { if len(c.ExtCommunityList) == 0 { @@ -1296,8 +1296,8 @@ func (s *LargeCommunitySet) List() []string { return list } -func (s *LargeCommunitySet) ToConfig() *config.LargeCommunitySet { - return &config.LargeCommunitySet{ +func (s *LargeCommunitySet) ToConfig() *oc.LargeCommunitySet { + return &oc.LargeCommunitySet{ LargeCommunitySetName: s.name, LargeCommunityList: s.List(), } @@ -1325,7 +1325,7 @@ func ParseLargeCommunityRegexp(arg string) (*regexp.Regexp, error) { return exp, nil } -func NewLargeCommunitySet(c config.LargeCommunitySet) (*LargeCommunitySet, error) { +func NewLargeCommunitySet(c oc.LargeCommunitySet) (*LargeCommunitySet, error) { name := c.LargeCommunitySetName if name == "" { if len(c.LargeCommunityList) == 0 { @@ -1475,7 +1475,7 @@ func (c *PrefixCondition) Evaluate(path *Path, _ *PolicyOptions) bool { func (c *PrefixCondition) Name() string { return c.set.name } -func NewPrefixCondition(c config.MatchPrefixSet) (*PrefixCondition, error) { +func NewPrefixCondition(c oc.MatchPrefixSet) (*PrefixCondition, error) { if c.PrefixSet == "" { return nil, nil } @@ -1541,7 +1541,7 @@ func (c *NeighborCondition) Evaluate(path *Path, options *PolicyOptions) bool { func (c *NeighborCondition) Name() string { return c.set.name } -func NewNeighborCondition(c config.MatchNeighborSet) (*NeighborCondition, error) { +func NewNeighborCondition(c oc.MatchNeighborSet) (*NeighborCondition, error) { if c.NeighborSet == "" { return nil, nil } @@ -1613,7 +1613,7 @@ func (c *AsPathCondition) Evaluate(path *Path, _ *PolicyOptions) bool { func (c *AsPathCondition) Name() string { return c.set.name } -func NewAsPathCondition(c config.MatchAsPathSet) (*AsPathCondition, error) { +func NewAsPathCondition(c oc.MatchAsPathSet) (*AsPathCondition, error) { if c.AsPathSet == "" { return nil, nil } @@ -1672,7 +1672,7 @@ func (c *CommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool { func (c *CommunityCondition) Name() string { return c.set.name } -func NewCommunityCondition(c config.MatchCommunitySet) (*CommunityCondition, error) { +func NewCommunityCondition(c oc.MatchCommunitySet) (*CommunityCondition, error) { if c.CommunitySet == "" { return nil, nil } @@ -1746,7 +1746,7 @@ func (c *ExtCommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool { func (c *ExtCommunityCondition) Name() string { return c.set.name } -func NewExtCommunityCondition(c config.MatchExtCommunitySet) (*ExtCommunityCondition, error) { +func NewExtCommunityCondition(c oc.MatchExtCommunitySet) (*ExtCommunityCondition, error) { if c.ExtCommunitySet == "" { return nil, nil } @@ -1807,7 +1807,7 @@ func (c *LargeCommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool { func (c *LargeCommunityCondition) Name() string { return c.set.name } -func NewLargeCommunityCondition(c config.MatchLargeCommunitySet) (*LargeCommunityCondition, error) { +func NewLargeCommunityCondition(c oc.MatchLargeCommunitySet) (*LargeCommunityCondition, error) { if c.LargeCommunitySet == "" { return nil, nil } @@ -1862,7 +1862,7 @@ func (c *AsPathLengthCondition) String() string { return fmt.Sprintf("%s%d", c.operator, c.length) } -func NewAsPathLengthCondition(c config.AsPathLength) (*AsPathLengthCondition, error) { +func NewAsPathLengthCondition(c oc.AsPathLength) (*AsPathLengthCondition, error) { if c.Value == 0 && c.Operator == "" { return nil, nil } @@ -1871,7 +1871,7 @@ func NewAsPathLengthCondition(c config.AsPathLength) (*AsPathLengthCondition, er return nil, fmt.Errorf("invalid as path length operator: %s", c.Operator) } else { // take mod 3 because we have extended openconfig attribute-comparison - // for simple configuration. see config.AttributeComparison definition + // for simple configuration. see oc.AttributeComparison definition op = AttributeComparison(i % 3) } return &AsPathLengthCondition{ @@ -1881,7 +1881,7 @@ func NewAsPathLengthCondition(c config.AsPathLength) (*AsPathLengthCondition, er } type RpkiValidationCondition struct { - result config.RpkiValidationResultType + result oc.RpkiValidationResultType } func (c *RpkiValidationCondition) Type() ConditionType { @@ -1905,8 +1905,8 @@ func (c *RpkiValidationCondition) String() string { return string(c.result) } -func NewRpkiValidationCondition(c config.RpkiValidationResultType) (*RpkiValidationCondition, error) { - if c == config.RpkiValidationResultType("") || c == config.RPKI_VALIDATION_RESULT_TYPE_NONE { +func NewRpkiValidationCondition(c oc.RpkiValidationResultType) (*RpkiValidationCondition, error) { + if c == oc.RpkiValidationResultType("") || c == oc.RPKI_VALIDATION_RESULT_TYPE_NONE { return nil, nil } return &RpkiValidationCondition{ @@ -1915,7 +1915,7 @@ func NewRpkiValidationCondition(c config.RpkiValidationResultType) (*RpkiValidat } type RouteTypeCondition struct { - typ config.RouteType + typ oc.RouteType } func (c *RouteTypeCondition) Type() ConditionType { @@ -1924,11 +1924,11 @@ func (c *RouteTypeCondition) Type() ConditionType { func (c *RouteTypeCondition) Evaluate(path *Path, _ *PolicyOptions) bool { switch c.typ { - case config.ROUTE_TYPE_LOCAL: + case oc.ROUTE_TYPE_LOCAL: return path.IsLocal() - case config.ROUTE_TYPE_INTERNAL: + case oc.ROUTE_TYPE_INTERNAL: return !path.IsLocal() && path.IsIBGP() - case config.ROUTE_TYPE_EXTERNAL: + case oc.ROUTE_TYPE_EXTERNAL: return !path.IsLocal() && !path.IsIBGP() } return false @@ -1944,8 +1944,8 @@ func (c *RouteTypeCondition) String() string { return string(c.typ) } -func NewRouteTypeCondition(c config.RouteType) (*RouteTypeCondition, error) { - if string(c) == "" || c == config.ROUTE_TYPE_NONE { +func NewRouteTypeCondition(c oc.RouteType) (*RouteTypeCondition, error) { + if string(c) == "" || c == oc.ROUTE_TYPE_NONE { return nil, nil } if err := c.Validate(); err != nil { @@ -1987,7 +1987,7 @@ func (c *AfiSafiInCondition) String() string { return strings.Join(tmp, " ") } -func NewAfiSafiInCondition(afiSafInConfig []config.AfiSafiType) (*AfiSafiInCondition, error) { +func NewAfiSafiInCondition(afiSafInConfig []oc.AfiSafiType) (*AfiSafiInCondition, error) { if afiSafInConfig == nil { return nil, nil } @@ -2037,14 +2037,14 @@ func (a *RoutingAction) String() string { return action } -func NewRoutingAction(c config.RouteDisposition) (*RoutingAction, error) { +func NewRoutingAction(c oc.RouteDisposition) (*RoutingAction, error) { var accept bool switch c { - case config.RouteDisposition(""), config.ROUTE_DISPOSITION_NONE: + case oc.RouteDisposition(""), oc.ROUTE_DISPOSITION_NONE: return nil, nil - case config.ROUTE_DISPOSITION_ACCEPT_ROUTE: + case oc.ROUTE_DISPOSITION_ACCEPT_ROUTE: accept = true - case config.ROUTE_DISPOSITION_REJECT_ROUTE: + case oc.ROUTE_DISPOSITION_REJECT_ROUTE: accept = false default: return nil, fmt.Errorf("invalid route disposition") @@ -2055,7 +2055,7 @@ func NewRoutingAction(c config.RouteDisposition) (*RoutingAction, error) { } type CommunityAction struct { - action config.BgpSetCommunityOptionType + action oc.BgpSetCommunityOptionType list []uint32 removeList []*regexp.Regexp } @@ -2127,17 +2127,17 @@ func (a *CommunityAction) Type() ActionType { func (a *CommunityAction) Apply(path *Path, _ *PolicyOptions) (*Path, error) { switch a.action { - case config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: path.SetCommunities(a.list, false) - case config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: RegexpRemoveCommunities(path, a.removeList) - case config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: path.SetCommunities(a.list, true) } return path, nil } -func (a *CommunityAction) ToConfig() *config.SetCommunity { +func (a *CommunityAction) ToConfig() *oc.SetCommunity { cs := make([]string, 0, len(a.list)+len(a.removeList)) for _, comm := range a.list { c := fmt.Sprintf("%d:%d", comm>>16, comm&0x0000ffff) @@ -2146,9 +2146,9 @@ func (a *CommunityAction) ToConfig() *config.SetCommunity { for _, exp := range a.removeList { cs = append(cs, exp.String()) } - return &config.SetCommunity{ + return &oc.SetCommunity{ Options: string(a.action), - SetCommunityMethod: config.SetCommunityMethod{CommunitiesList: cs}, + SetCommunityMethod: oc.SetCommunityMethod{CommunitiesList: cs}, } } @@ -2165,7 +2165,7 @@ func (a *CommunityAction) String() string { return fmt.Sprintf("%s[%s]", a.action, l) } -func NewCommunityAction(c config.SetCommunity) (*CommunityAction, error) { +func NewCommunityAction(c oc.SetCommunity) (*CommunityAction, error) { a, ok := CommunityOptionValueMap[strings.ToLower(c.Options)] if !ok { if len(c.SetCommunityMethod.CommunitiesList) == 0 { @@ -2175,13 +2175,13 @@ func NewCommunityAction(c config.SetCommunity) (*CommunityAction, error) { } var list []uint32 var removeList []*regexp.Regexp - if a == config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { + if a == oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { removeList = make([]*regexp.Regexp, 0, len(c.SetCommunityMethod.CommunitiesList)) } else { list = make([]uint32, 0, len(c.SetCommunityMethod.CommunitiesList)) } for _, x := range c.SetCommunityMethod.CommunitiesList { - if a == config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { + if a == oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { exp, err := ParseCommunityRegexp(x) if err != nil { return nil, err @@ -2203,7 +2203,7 @@ func NewCommunityAction(c config.SetCommunity) (*CommunityAction, error) { } type ExtCommunityAction struct { - action config.BgpSetCommunityOptionType + action oc.BgpSetCommunityOptionType list []bgp.ExtendedCommunityInterface removeList []*regexp.Regexp subtypeList []bgp.ExtendedCommunityAttrSubType @@ -2215,17 +2215,17 @@ func (a *ExtCommunityAction) Type() ActionType { func (a *ExtCommunityAction) Apply(path *Path, _ *PolicyOptions) (*Path, error) { switch a.action { - case config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: path.SetExtCommunities(a.list, false) - case config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: RegexpRemoveExtCommunities(path, a.removeList, a.subtypeList) - case config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: path.SetExtCommunities(a.list, true) } return path, nil } -func (a *ExtCommunityAction) ToConfig() *config.SetExtCommunity { +func (a *ExtCommunityAction) ToConfig() *oc.SetExtCommunity { cs := make([]string, 0, len(a.list)+len(a.removeList)) f := func(idx int, arg string) string { switch a.subtypeList[idx] { @@ -2249,9 +2249,9 @@ func (a *ExtCommunityAction) ToConfig() *config.SetExtCommunity { for idx, exp := range a.removeList { cs = append(cs, f(idx, exp.String())) } - return &config.SetExtCommunity{ + return &oc.SetExtCommunity{ Options: string(a.action), - SetExtCommunityMethod: config.SetExtCommunityMethod{ + SetExtCommunityMethod: oc.SetExtCommunityMethod{ CommunitiesList: cs, }, } @@ -2267,7 +2267,7 @@ func (a *ExtCommunityAction) MarshalJSON() ([]byte, error) { return json.Marshal(a.ToConfig()) } -func NewExtCommunityAction(c config.SetExtCommunity) (*ExtCommunityAction, error) { +func NewExtCommunityAction(c oc.SetExtCommunity) (*ExtCommunityAction, error) { a, ok := CommunityOptionValueMap[strings.ToLower(c.Options)] if !ok { if len(c.SetExtCommunityMethod.CommunitiesList) == 0 { @@ -2278,13 +2278,13 @@ func NewExtCommunityAction(c config.SetExtCommunity) (*ExtCommunityAction, error var list []bgp.ExtendedCommunityInterface var removeList []*regexp.Regexp subtypeList := make([]bgp.ExtendedCommunityAttrSubType, 0, len(c.SetExtCommunityMethod.CommunitiesList)) - if a == config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { + if a == oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { removeList = make([]*regexp.Regexp, 0, len(c.SetExtCommunityMethod.CommunitiesList)) } else { list = make([]bgp.ExtendedCommunityInterface, 0, len(c.SetExtCommunityMethod.CommunitiesList)) } for _, x := range c.SetExtCommunityMethod.CommunitiesList { - if a == config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { + if a == oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { subtype, exp, err := ParseExtCommunityRegexp(x) if err != nil { return nil, err @@ -2310,7 +2310,7 @@ func NewExtCommunityAction(c config.SetExtCommunity) (*ExtCommunityAction, error } type LargeCommunityAction struct { - action config.BgpSetCommunityOptionType + action oc.BgpSetCommunityOptionType list []*bgp.LargeCommunity removeList []*regexp.Regexp } @@ -2321,17 +2321,17 @@ func (a *LargeCommunityAction) Type() ActionType { func (a *LargeCommunityAction) Apply(path *Path, _ *PolicyOptions) (*Path, error) { switch a.action { - case config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD: path.SetLargeCommunities(a.list, false) - case config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE: RegexpRemoveLargeCommunities(path, a.removeList) - case config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: + case oc.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: path.SetLargeCommunities(a.list, true) } return path, nil } -func (a *LargeCommunityAction) ToConfig() *config.SetLargeCommunity { +func (a *LargeCommunityAction) ToConfig() *oc.SetLargeCommunity { cs := make([]string, 0, len(a.list)+len(a.removeList)) for _, comm := range a.list { cs = append(cs, comm.String()) @@ -2339,9 +2339,9 @@ func (a *LargeCommunityAction) ToConfig() *config.SetLargeCommunity { for _, exp := range a.removeList { cs = append(cs, exp.String()) } - return &config.SetLargeCommunity{ - SetLargeCommunityMethod: config.SetLargeCommunityMethod{CommunitiesList: cs}, - Options: config.BgpSetCommunityOptionType(a.action), + return &oc.SetLargeCommunity{ + SetLargeCommunityMethod: oc.SetLargeCommunityMethod{CommunitiesList: cs}, + Options: oc.BgpSetCommunityOptionType(a.action), } } @@ -2355,7 +2355,7 @@ func (a *LargeCommunityAction) MarshalJSON() ([]byte, error) { return json.Marshal(a.ToConfig()) } -func NewLargeCommunityAction(c config.SetLargeCommunity) (*LargeCommunityAction, error) { +func NewLargeCommunityAction(c oc.SetLargeCommunity) (*LargeCommunityAction, error) { a, ok := CommunityOptionValueMap[strings.ToLower(string(c.Options))] if !ok { if len(c.SetLargeCommunityMethod.CommunitiesList) == 0 { @@ -2365,13 +2365,13 @@ func NewLargeCommunityAction(c config.SetLargeCommunity) (*LargeCommunityAction, } var list []*bgp.LargeCommunity var removeList []*regexp.Regexp - if a == config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { + if a == oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { removeList = make([]*regexp.Regexp, 0, len(c.SetLargeCommunityMethod.CommunitiesList)) } else { list = make([]*bgp.LargeCommunity, 0, len(c.SetLargeCommunityMethod.CommunitiesList)) } for _, x := range c.SetLargeCommunityMethod.CommunitiesList { - if a == config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { + if a == oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE { exp, err := ParseLargeCommunityRegexp(x) if err != nil { return nil, err @@ -2416,11 +2416,11 @@ func (a *MedAction) Apply(path *Path, _ *PolicyOptions) (*Path, error) { return path, nil } -func (a *MedAction) ToConfig() config.BgpSetMedType { +func (a *MedAction) ToConfig() oc.BgpSetMedType { if a.action == MED_ACTION_MOD && a.value > 0 { - return config.BgpSetMedType(fmt.Sprintf("+%d", a.value)) + return oc.BgpSetMedType(fmt.Sprintf("+%d", a.value)) } - return config.BgpSetMedType(fmt.Sprintf("%d", a.value)) + return oc.BgpSetMedType(fmt.Sprintf("%d", a.value)) } func (a *MedAction) String() string { @@ -2433,7 +2433,7 @@ func (a *MedAction) MarshalJSON() ([]byte, error) { var _regexpParseMedAction = regexp.MustCompile(`^(\+|\-)?(\d+)$`) -func NewMedAction(c config.BgpSetMedType) (*MedAction, error) { +func NewMedAction(c oc.BgpSetMedType) (*MedAction, error) { if string(c) == "" { return nil, nil } @@ -2523,8 +2523,8 @@ func (a *AsPathPrependAction) Apply(path *Path, option *PolicyOptions) (*Path, e return path, nil } -func (a *AsPathPrependAction) ToConfig() *config.SetAsPathPrepend { - return &config.SetAsPathPrepend{ +func (a *AsPathPrependAction) ToConfig() *oc.SetAsPathPrepend { + return &oc.SetAsPathPrepend{ RepeatN: uint8(a.repeat), As: func() string { if a.useLeftMost { @@ -2546,7 +2546,7 @@ func (a *AsPathPrependAction) MarshalJSON() ([]byte, error) { // NewAsPathPrependAction creates AsPathPrependAction object. // If ASN cannot be parsed, nil will be returned. -func NewAsPathPrependAction(action config.SetAsPathPrepend) (*AsPathPrependAction, error) { +func NewAsPathPrependAction(action oc.SetAsPathPrepend) (*AsPathPrependAction, error) { a := &AsPathPrependAction{ repeat: action.RepeatN, } @@ -2595,14 +2595,14 @@ func (a *NexthopAction) Apply(path *Path, options *PolicyOptions) (*Path, error) return path, nil } -func (a *NexthopAction) ToConfig() config.BgpNextHopType { +func (a *NexthopAction) ToConfig() oc.BgpNextHopType { if a.self { - return config.BgpNextHopType("self") + return oc.BgpNextHopType("self") } if a.unchanged { - return config.BgpNextHopType("unchanged") + return oc.BgpNextHopType("unchanged") } - return config.BgpNextHopType(a.value.String()) + return oc.BgpNextHopType(a.value.String()) } func (a *NexthopAction) String() string { @@ -2613,7 +2613,7 @@ func (a *NexthopAction) MarshalJSON() ([]byte, error) { return json.Marshal(a.ToConfig()) } -func NewNexthopAction(c config.BgpNextHopType) (*NexthopAction, error) { +func NewNexthopAction(c oc.BgpNextHopType) (*NexthopAction, error) { switch strings.ToLower(string(c)) { case "": return nil, nil @@ -2682,27 +2682,27 @@ func (s *Statement) Apply(logger log.Logger, path *Path, options *PolicyOptions) return ROUTE_TYPE_NONE, path } -func (s *Statement) ToConfig() *config.Statement { - return &config.Statement{ +func (s *Statement) ToConfig() *oc.Statement { + return &oc.Statement{ Name: s.Name, - Conditions: func() config.Conditions { - cond := config.Conditions{} + Conditions: func() oc.Conditions { + cond := oc.Conditions{} for _, c := range s.Conditions { switch v := c.(type) { case *PrefixCondition: - cond.MatchPrefixSet = config.MatchPrefixSet{PrefixSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} + cond.MatchPrefixSet = oc.MatchPrefixSet{PrefixSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} case *NeighborCondition: - cond.MatchNeighborSet = config.MatchNeighborSet{NeighborSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} + cond.MatchNeighborSet = oc.MatchNeighborSet{NeighborSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()} case *AsPathLengthCondition: - cond.BgpConditions.AsPathLength = config.AsPathLength{Operator: config.IntToAttributeComparisonMap[int(v.operator)], Value: v.length} + cond.BgpConditions.AsPathLength = oc.AsPathLength{Operator: oc.IntToAttributeComparisonMap[int(v.operator)], Value: v.length} case *AsPathCondition: - cond.BgpConditions.MatchAsPathSet = config.MatchAsPathSet{AsPathSet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]} + cond.BgpConditions.MatchAsPathSet = oc.MatchAsPathSet{AsPathSet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} case *CommunityCondition: - cond.BgpConditions.MatchCommunitySet = config.MatchCommunitySet{CommunitySet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]} + cond.BgpConditions.MatchCommunitySet = oc.MatchCommunitySet{CommunitySet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} case *ExtCommunityCondition: - cond.BgpConditions.MatchExtCommunitySet = config.MatchExtCommunitySet{ExtCommunitySet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]} + cond.BgpConditions.MatchExtCommunitySet = oc.MatchExtCommunitySet{ExtCommunitySet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} case *LargeCommunityCondition: - cond.BgpConditions.MatchLargeCommunitySet = config.MatchLargeCommunitySet{LargeCommunitySet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]} + cond.BgpConditions.MatchLargeCommunitySet = oc.MatchLargeCommunitySet{LargeCommunitySet: v.set.Name(), MatchSetOptions: oc.IntToMatchSetOptionsTypeMap[int(v.option)]} case *NextHopCondition: cond.BgpConditions.NextHopInList = v.set.List() case *RpkiValidationCondition: @@ -2710,26 +2710,26 @@ func (s *Statement) ToConfig() *config.Statement { case *RouteTypeCondition: cond.BgpConditions.RouteType = v.typ case *AfiSafiInCondition: - res := make([]config.AfiSafiType, 0, len(v.routeFamilies)) + res := make([]oc.AfiSafiType, 0, len(v.routeFamilies)) for _, rf := range v.routeFamilies { - res = append(res, config.AfiSafiType(rf.String())) + res = append(res, oc.AfiSafiType(rf.String())) } cond.BgpConditions.AfiSafiInList = res } } return cond }(), - Actions: func() config.Actions { - act := config.Actions{} + Actions: func() oc.Actions { + act := oc.Actions{} if s.RouteAction != nil && !reflect.ValueOf(s.RouteAction).IsNil() { a := s.RouteAction.(*RoutingAction) if a.AcceptRoute { - act.RouteDisposition = config.ROUTE_DISPOSITION_ACCEPT_ROUTE + act.RouteDisposition = oc.ROUTE_DISPOSITION_ACCEPT_ROUTE } else { - act.RouteDisposition = config.ROUTE_DISPOSITION_REJECT_ROUTE + act.RouteDisposition = oc.ROUTE_DISPOSITION_REJECT_ROUTE } } else { - act.RouteDisposition = config.ROUTE_DISPOSITION_NONE + act.RouteDisposition = oc.ROUTE_DISPOSITION_NONE } for _, a := range s.ModActions { switch v := a.(type) { @@ -2877,7 +2877,7 @@ func (lhs *Statement) Replace(rhs *Statement) error { return lhs.mod(REPLACE, rhs) } -func NewStatement(c config.Statement) (*Statement, error) { +func NewStatement(c oc.Statement) (*Statement, error) { if c.Name == "" { return nil, fmt.Errorf("empty statement name") } @@ -2994,12 +2994,12 @@ func (p *Policy) Apply(logger log.Logger, path *Path, options *PolicyOptions) (R return ROUTE_TYPE_NONE, path } -func (p *Policy) ToConfig() *config.PolicyDefinition { - ss := make([]config.Statement, 0, len(p.Statements)) +func (p *Policy) ToConfig() *oc.PolicyDefinition { + ss := make([]oc.Statement, 0, len(p.Statements)) for _, s := range p.Statements { ss = append(ss, *s.ToConfig()) } - return &config.PolicyDefinition{ + return &oc.PolicyDefinition{ Name: p.Name, Statements: ss, } @@ -3050,7 +3050,7 @@ func (p *Policy) MarshalJSON() ([]byte, error) { return json.Marshal(p.ToConfig()) } -func NewPolicy(c config.PolicyDefinition) (*Policy, error) { +func NewPolicy(c oc.PolicyDefinition) (*Policy, error) { if c.Name == "" { return nil, fmt.Errorf("empty policy name") } @@ -3197,9 +3197,9 @@ func (r *RoutingPolicy) setDefaultPolicy(id string, dir PolicyDirection, typ Rou return nil } -func (r *RoutingPolicy) getAssignmentFromConfig(dir PolicyDirection, a config.ApplyPolicy) ([]*Policy, RouteType, error) { +func (r *RoutingPolicy) getAssignmentFromConfig(dir PolicyDirection, a oc.ApplyPolicy) ([]*Policy, RouteType, error) { var names []string - var cdef config.DefaultPolicyType + var cdef oc.DefaultPolicyType def := ROUTE_TYPE_ACCEPT c := a.Config switch dir { @@ -3212,7 +3212,7 @@ func (r *RoutingPolicy) getAssignmentFromConfig(dir PolicyDirection, a config.Ap default: return nil, def, fmt.Errorf("invalid policy direction") } - if cdef == config.DEFAULT_POLICY_TYPE_REJECT_ROUTE { + if cdef == oc.DEFAULT_POLICY_TYPE_REJECT_ROUTE { def = ROUTE_TYPE_REJECT } ps := make([]*Policy, 0, len(names)) @@ -3314,7 +3314,7 @@ func (r *RoutingPolicy) statementInUse(x *Statement) bool { return false } -func (r *RoutingPolicy) reload(c config.RoutingPolicy) error { +func (r *RoutingPolicy) reload(c oc.RoutingPolicy) error { dmap := make(map[DefinedType]map[string]DefinedSet) dmap[DEFINED_TYPE_PREFIX] = make(map[string]DefinedSet) d := c.DefinedSets @@ -3437,7 +3437,7 @@ func (r *RoutingPolicy) reload(c config.RoutingPolicy) error { return nil } -func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*config.DefinedSets, error) { +func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*oc.DefinedSets, error) { dl, err := func() (DefinedSetList, error) { r.mu.RLock() defer r.mu.RUnlock() @@ -3459,14 +3459,14 @@ func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*config.Def sort.Sort(dl) - sets := &config.DefinedSets{ - PrefixSets: make([]config.PrefixSet, 0), - NeighborSets: make([]config.NeighborSet, 0), - BgpDefinedSets: config.BgpDefinedSets{ - CommunitySets: make([]config.CommunitySet, 0), - ExtCommunitySets: make([]config.ExtCommunitySet, 0), - LargeCommunitySets: make([]config.LargeCommunitySet, 0), - AsPathSets: make([]config.AsPathSet, 0), + sets := &oc.DefinedSets{ + PrefixSets: make([]oc.PrefixSet, 0), + NeighborSets: make([]oc.NeighborSet, 0), + BgpDefinedSets: oc.BgpDefinedSets{ + CommunitySets: make([]oc.CommunitySet, 0), + ExtCommunitySets: make([]oc.ExtCommunitySet, 0), + LargeCommunitySets: make([]oc.LargeCommunitySet, 0), + AsPathSets: make([]oc.AsPathSet, 0), }, } for _, s := range dl { @@ -3533,11 +3533,11 @@ func (r *RoutingPolicy) DeleteDefinedSet(a DefinedSet, all bool) (err error) { return err } -func (r *RoutingPolicy) GetStatement(name string) []*config.Statement { +func (r *RoutingPolicy) GetStatement(name string) []*oc.Statement { r.mu.RLock() defer r.mu.RUnlock() - l := make([]*config.Statement, 0, len(r.statementMap)) + l := make([]*oc.Statement, 0, len(r.statementMap)) for _, st := range r.statementMap { if name != "" && name != st.Name { continue @@ -3589,7 +3589,7 @@ func (r *RoutingPolicy) DeleteStatement(st *Statement, all bool) (err error) { return err } -func (r *RoutingPolicy) GetPolicy(name string) []*config.PolicyDefinition { +func (r *RoutingPolicy) GetPolicy(name string) []*oc.PolicyDefinition { ps := func() Policies { r.mu.RLock() defer r.mu.RUnlock() @@ -3606,7 +3606,7 @@ func (r *RoutingPolicy) GetPolicy(name string) []*config.PolicyDefinition { sort.Sort(ps) - l := make([]*config.PolicyDefinition, 0, len(ps)) + l := make([]*oc.PolicyDefinition, 0, len(ps)) for _, p := range ps { l = append(l, p.ToConfig()) } @@ -3711,7 +3711,7 @@ func (r *RoutingPolicy) GetPolicyAssignment(id string, dir PolicyDirection) (Rou return rt, l, nil } -func (r *RoutingPolicy) AddPolicyAssignment(id string, dir PolicyDirection, policies []*config.PolicyDefinition, def RouteType) (err error) { +func (r *RoutingPolicy) AddPolicyAssignment(id string, dir PolicyDirection, policies []*oc.PolicyDefinition, def RouteType) (err error) { r.mu.Lock() defer r.mu.Unlock() @@ -3751,7 +3751,7 @@ func (r *RoutingPolicy) AddPolicyAssignment(id string, dir PolicyDirection, poli return err } -func (r *RoutingPolicy) DeletePolicyAssignment(id string, dir PolicyDirection, policies []*config.PolicyDefinition, all bool) (err error) { +func (r *RoutingPolicy) DeletePolicyAssignment(id string, dir PolicyDirection, policies []*oc.PolicyDefinition, all bool) (err error) { r.mu.Lock() defer r.mu.Unlock() @@ -3802,7 +3802,7 @@ func (r *RoutingPolicy) DeletePolicyAssignment(id string, dir PolicyDirection, p return err } -func (r *RoutingPolicy) SetPolicyAssignment(id string, dir PolicyDirection, policies []*config.PolicyDefinition, def RouteType) (err error) { +func (r *RoutingPolicy) SetPolicyAssignment(id string, dir PolicyDirection, policies []*oc.PolicyDefinition, def RouteType) (err error) { r.mu.Lock() defer r.mu.Unlock() @@ -3833,7 +3833,7 @@ func (r *RoutingPolicy) Initialize() error { r.mu.Lock() defer r.mu.Unlock() - if err := r.reload(config.RoutingPolicy{}); err != nil { + if err := r.reload(oc.RoutingPolicy{}); err != nil { r.logger.Error("failed to create routing policy", log.Fields{ "Topic": "Policy", @@ -3843,7 +3843,7 @@ func (r *RoutingPolicy) Initialize() error { return nil } -func (r *RoutingPolicy) setPeerPolicy(id string, c config.ApplyPolicy) { +func (r *RoutingPolicy) setPeerPolicy(id string, c oc.ApplyPolicy) { for _, dir := range []PolicyDirection{POLICY_DIRECTION_IMPORT, POLICY_DIRECTION_EXPORT} { ps, def, err := r.getAssignmentFromConfig(dir, c) if err != nil { @@ -3859,7 +3859,7 @@ func (r *RoutingPolicy) setPeerPolicy(id string, c config.ApplyPolicy) { } } -func (r *RoutingPolicy) SetPeerPolicy(peerId string, c config.ApplyPolicy) error { +func (r *RoutingPolicy) SetPeerPolicy(peerId string, c oc.ApplyPolicy) error { r.mu.Lock() defer r.mu.Unlock() @@ -3867,7 +3867,7 @@ func (r *RoutingPolicy) SetPeerPolicy(peerId string, c config.ApplyPolicy) error return nil } -func (r *RoutingPolicy) Reset(rp *config.RoutingPolicy, ap map[string]config.ApplyPolicy) error { +func (r *RoutingPolicy) Reset(rp *oc.RoutingPolicy, ap map[string]oc.ApplyPolicy) error { if rp == nil { return fmt.Errorf("routing Policy is nil in call to Reset") } @@ -3907,13 +3907,13 @@ func CanImportToVrf(v *Vrf, path *Path) bool { } return ret } - set, _ := NewExtCommunitySet(config.ExtCommunitySet{ + set, _ := NewExtCommunitySet(oc.ExtCommunitySet{ ExtCommunitySetName: v.Name, ExtCommunityList: f(v.ImportRt), }) - matchSet := config.MatchExtCommunitySet{ + matchSet := oc.MatchExtCommunitySet{ ExtCommunitySet: v.Name, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_TYPE_ANY, } c, _ := NewExtCommunityCondition(matchSet) c.set = set @@ -3929,7 +3929,7 @@ type PolicyAssignment struct { var _regexpMedActionType = regexp.MustCompile(`([+-]?)(\d+)`) -func toStatementApi(s *config.Statement) *api.Statement { +func toStatementApi(s *oc.Statement) *api.Statement { cs := &api.Conditions{} o, _ := NewMatchOption(s.Conditions.MatchPrefixSet.MatchSetOptions) if s.Conditions.MatchPrefixSet.PrefixSet != "" { @@ -3995,9 +3995,9 @@ func toStatementApi(s *config.Statement) *api.Statement { as := &api.Actions{ RouteAction: func() api.RouteAction { switch s.Actions.RouteDisposition { - case config.ROUTE_DISPOSITION_ACCEPT_ROUTE: + case oc.ROUTE_DISPOSITION_ACCEPT_ROUTE: return api.RouteAction_ACCEPT - case config.ROUTE_DISPOSITION_REJECT_ROUTE: + case oc.ROUTE_DISPOSITION_REJECT_ROUTE: return api.RouteAction_REJECT } return api.RouteAction_NONE @@ -4007,7 +4007,7 @@ func toStatementApi(s *config.Statement) *api.Statement { return nil } return &api.CommunityAction{ - Type: api.CommunityAction_Type(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetCommunity.Options)]), + Type: api.CommunityAction_Type(oc.BgpSetCommunityOptionTypeToIntMap[oc.BgpSetCommunityOptionType(s.Actions.BgpActions.SetCommunity.Options)]), Communities: s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList} }(), Med: func() *api.MedAction { @@ -4055,7 +4055,7 @@ func toStatementApi(s *config.Statement) *api.Statement { return nil } return &api.CommunityAction{ - Type: api.CommunityAction_Type(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetExtCommunity.Options)]), + Type: api.CommunityAction_Type(oc.BgpSetCommunityOptionTypeToIntMap[oc.BgpSetCommunityOptionType(s.Actions.BgpActions.SetExtCommunity.Options)]), Communities: s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.CommunitiesList, } }(), @@ -4064,7 +4064,7 @@ func toStatementApi(s *config.Statement) *api.Statement { return nil } return &api.CommunityAction{ - Type: api.CommunityAction_Type(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetLargeCommunity.Options)]), + Type: api.CommunityAction_Type(oc.BgpSetCommunityOptionTypeToIntMap[oc.BgpSetCommunityOptionType(s.Actions.BgpActions.SetLargeCommunity.Options)]), Communities: s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList, } }(), @@ -4105,7 +4105,7 @@ func NewAPIPolicyFromTableStruct(p *Policy) *api.Policy { return ToPolicyApi(p.ToConfig()) } -func ToPolicyApi(p *config.PolicyDefinition) *api.Policy { +func ToPolicyApi(p *oc.PolicyDefinition) *api.Policy { return &api.Policy{ Name: p.Name, Statements: func() []*api.Statement { @@ -4149,8 +4149,8 @@ func NewAPIPolicyAssignmentFromTableStruct(t *PolicyAssignment) *api.PolicyAssig } } -func NewAPIRoutingPolicyFromConfigStruct(c *config.RoutingPolicy) (*api.RoutingPolicy, error) { - definedSets, err := config.NewAPIDefinedSetsFromConfigStruct(&c.DefinedSets) +func NewAPIRoutingPolicyFromConfigStruct(c *oc.RoutingPolicy) (*api.RoutingPolicy, error) { + definedSets, err := oc.NewAPIDefinedSetsFromConfigStruct(&c.DefinedSets) if err != nil { return nil, err } diff --git a/internal/pkg/table/policy_test.go b/internal/pkg/table/policy_test.go index a45b0a92c..567025ac3 100644 --- a/internal/pkg/table/policy_test.go +++ b/internal/pkg/table/policy_test.go @@ -24,7 +24,7 @@ import ( "testing" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/stretchr/testify/assert" @@ -61,13 +61,13 @@ func TestPrefixCalcurateNoRange(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/24", MasklengthRange: ""}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/24", MasklengthRange: ""}) match1 := pl1.Match(path) assert.Equal(t, true, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/23", MasklengthRange: ""}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/23", MasklengthRange: ""}) match2 := pl2.Match(path) assert.Equal(t, false, match2) - pl3, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..24"}) + pl3, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..24"}) match3 := pl3.Match(path) assert.Equal(t, true, match3) } @@ -85,10 +85,10 @@ func TestPrefixCalcurateAddress(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "10.11.0.0/16", MasklengthRange: "21..24"}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "10.11.0.0/16", MasklengthRange: "21..24"}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..24"}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..24"}) match2 := pl2.Match(path) assert.Equal(t, true, match2) } @@ -106,10 +106,10 @@ func TestPrefixCalcurateLength(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.64.0/24", MasklengthRange: "21..24"}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.64.0/24", MasklengthRange: "21..24"}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.64.0/16", MasklengthRange: "21..24"}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.64.0/16", MasklengthRange: "21..24"}) match2 := pl2.Match(path) assert.Equal(t, true, match2) } @@ -127,13 +127,13 @@ func TestPrefixCalcurateLengthRange(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..23"}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..23"}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "25..26"}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "25..26"}) match2 := pl2.Match(path) assert.Equal(t, false, match2) - pl3, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..24"}) + pl3, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/16", MasklengthRange: "21..24"}) match3 := pl3.Match(path) assert.Equal(t, true, match3) } @@ -151,13 +151,13 @@ func TestPrefixCalcurateNoRangeIPv6(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: ""}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: ""}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123:1::/64", MasklengthRange: ""}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123:1::/64", MasklengthRange: ""}) match2 := pl2.Match(path) assert.Equal(t, true, match2) - pl3, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "64..80"}) + pl3, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "64..80"}) match3 := pl3.Match(path) assert.Equal(t, true, match3) } @@ -175,10 +175,10 @@ func TestPrefixCalcurateAddressIPv6(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:128::/48", MasklengthRange: "64..80"}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:128::/48", MasklengthRange: "64..80"}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "64..80"}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "64..80"}) match2 := pl2.Match(path) assert.Equal(t, true, match2) } @@ -196,10 +196,10 @@ func TestPrefixCalcurateLengthIPv6(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123:64::/64", MasklengthRange: "64..80"}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123:64::/64", MasklengthRange: "64..80"}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123:64::/48", MasklengthRange: "64..80"}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123:64::/48", MasklengthRange: "64..80"}) match2 := pl2.Match(path) assert.Equal(t, true, match2) } @@ -217,13 +217,13 @@ func TestPrefixCalcurateLengthRangeIPv6(t *testing.T) { updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nil) path := ProcessMessage(updateMsg, peer, time.Now())[0] // test - pl1, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "62..63"}) + pl1, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "62..63"}) match1 := pl1.Match(path) assert.Equal(t, false, match1) - pl2, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "65..66"}) + pl2, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "65..66"}) match2 := pl2.Match(path) assert.Equal(t, false, match2) - pl3, _ := NewPrefix(config.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "63..65"}) + pl3, _ := NewPrefix(oc.Prefix{IpPrefix: "2001:123:123::/48", MasklengthRange: "63..65"}) match3 := pl3.Match(path) assert.Equal(t, true, match3) } @@ -244,9 +244,9 @@ func TestPolicyNotMatch(t *testing.T) { // create policy ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", false) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -274,9 +274,9 @@ func TestPolicyMatchAndReject(t *testing.T) { // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", false) pd := createPolicyDefinition("pd1", s) @@ -305,9 +305,9 @@ func TestPolicyMatchAndAccept(t *testing.T) { // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) pd := createPolicyDefinition("pd1", s) @@ -348,8 +348,8 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) { // create policy ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} s := createStatement("statement1", "ps1", "", false) pd := createPolicyDefinition("pd1", s) @@ -395,8 +395,8 @@ func TestPolicyRejectOnlyNeighborSet(t *testing.T) { // create policy ns := createNeighborSet("ns1", "10.0.1.1") - ds := config.DefinedSets{} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "", "ns1", false) pd := createPolicyDefinition("pd1", s) @@ -445,9 +445,9 @@ func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) { psIPv6 := createPrefixSet("psIPv6", "2001:123:123::/48", "64..80") nsIPv6 := createNeighborSet("nsIPv6", "2001::192:168:50:1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{psIPv4, psIPv6} - ds.NeighborSets = []config.NeighborSet{nsIPv4, nsIPv6} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{psIPv4, psIPv6} + ds.NeighborSets = []oc.NeighborSet{nsIPv4, nsIPv6} stIPv4 := createStatement("statement1", "psIPv4", "nsIPv4", false) stIPv6 := createStatement("statement2", "psIPv6", "nsIPv6", false) @@ -488,7 +488,7 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) { path := ProcessMessage(updateMsg, peer, time.Now())[0] // create match condition - asPathLength := config.AsPathLength{ + asPathLength := oc.AsPathLength{ Operator: "eq", Value: 5, } @@ -498,7 +498,7 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) { assert.Equal(t, true, c.Evaluate(path, nil)) // create match condition - asPathLength = config.AsPathLength{ + asPathLength = oc.AsPathLength{ Operator: "ge", Value: 3, } @@ -508,7 +508,7 @@ func TestAsPathLengthConditionEvaluate(t *testing.T) { assert.Equal(t, true, c.Evaluate(path, nil)) // create match condition - asPathLength = config.AsPathLength{ + asPathLength = oc.AsPathLength{ Operator: "le", Value: 3, } @@ -534,9 +534,9 @@ func TestPolicyMatchAndAcceptNextHop(t *testing.T) { // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.1/32"} pd := createPolicyDefinition("pd1", s) @@ -566,9 +566,9 @@ func TestPolicyMatchAndRejectNextHop(t *testing.T) { // create policy ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Conditions.BgpConditions.NextHopInList = []string{"10.0.0.12"} pd := createPolicyDefinition("pd1", s) @@ -604,12 +604,12 @@ func TestAsPathLengthConditionWithOtherCondition(t *testing.T) { ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} // create match condition - asPathLength := config.AsPathLength{ + asPathLength := oc.AsPathLength{ Operator: "le", Value: 10, } @@ -659,7 +659,7 @@ func TestAs4PathLengthConditionEvaluate(t *testing.T) { path := ProcessMessage(updateMsg, peer, time.Now())[0] // create match condition - asPathLength := config.AsPathLength{ + asPathLength := oc.AsPathLength{ Operator: "eq", Value: 5, } @@ -669,7 +669,7 @@ func TestAs4PathLengthConditionEvaluate(t *testing.T) { assert.Equal(t, true, c.Evaluate(path, nil)) // create match condition - asPathLength = config.AsPathLength{ + asPathLength = oc.AsPathLength{ Operator: "ge", Value: 3, } @@ -679,7 +679,7 @@ func TestAs4PathLengthConditionEvaluate(t *testing.T) { assert.Equal(t, true, c.Evaluate(path, nil)) // create match condition - asPathLength = config.AsPathLength{ + asPathLength = oc.AsPathLength{ Operator: "le", Value: 3, } @@ -730,12 +730,12 @@ func TestAs4PathLengthConditionWithOtherCondition(t *testing.T) { ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} // create match condition - asPathLength := config.AsPathLength{ + asPathLength := oc.AsPathLength{ Operator: "le", Value: 10, } @@ -784,45 +784,45 @@ func TestAsPathConditionEvaluate(t *testing.T) { path2 := ProcessMessage(updateMsg2, peer, time.Now())[0] // create match condition - asPathSet1 := config.AsPathSet{ + asPathSet1 := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{"^65001"}, } - asPathSet2 := config.AsPathSet{ + asPathSet2 := oc.AsPathSet{ AsPathSetName: "asset2", AsPathList: []string{"65005$"}, } - asPathSet3 := config.AsPathSet{ + asPathSet3 := oc.AsPathSet{ AsPathSetName: "asset3", AsPathList: []string{"65004", "65005$"}, } - asPathSet4 := config.AsPathSet{ + asPathSet4 := oc.AsPathSet{ AsPathSetName: "asset4", AsPathList: []string{"65000$"}, } - asPathSet5 := config.AsPathSet{ + asPathSet5 := oc.AsPathSet{ AsPathSetName: "asset5", AsPathList: []string{"65010"}, } - asPathSet6 := config.AsPathSet{ + asPathSet6 := oc.AsPathSet{ AsPathSetName: "asset6", AsPathList: []string{"^65010$"}, } m := make(map[string]DefinedSet) - for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3, + for _, s := range []oc.AsPathSet{asPathSet1, asPathSet2, asPathSet3, asPathSet4, asPathSet5, asPathSet6} { a, _ := NewAsPathSet(s) m[s.AsPathSetName] = a } - createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCondition { - matchSet := config.MatchAsPathSet{} + createAspathC := func(name string, option oc.MatchSetOptionsType) *AsPathCondition { + matchSet := oc.MatchAsPathSet{} matchSet.AsPathSet = name matchSet.MatchSetOptions = option p, _ := NewAsPathCondition(matchSet) @@ -832,14 +832,14 @@ func TestAsPathConditionEvaluate(t *testing.T) { return p } - p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY) - p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ALL) - p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT) + p1 := createAspathC("asset1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createAspathC("asset2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p4 := createAspathC("asset4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createAspathC("asset5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createAspathC("asset6", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p7 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ALL) + p8 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_INVERT) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -872,60 +872,60 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) { path1 := ProcessMessage(updateMsg1, peer, time.Now())[0] // create match condition - asPathSet1 := config.AsPathSet{ + asPathSet1 := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{"^65001_65000"}, } - asPathSet2 := config.AsPathSet{ + asPathSet2 := oc.AsPathSet{ AsPathSetName: "asset2", AsPathList: []string{"65004_65005$"}, } - asPathSet3 := config.AsPathSet{ + asPathSet3 := oc.AsPathSet{ AsPathSetName: "asset3", AsPathList: []string{"65001_65000_54000"}, } - asPathSet4 := config.AsPathSet{ + asPathSet4 := oc.AsPathSet{ AsPathSetName: "asset4", AsPathList: []string{"54000_65004_65005"}, } - asPathSet5 := config.AsPathSet{ + asPathSet5 := oc.AsPathSet{ AsPathSetName: "asset5", AsPathList: []string{"^65001 65000 54000 65004 65005$"}, } - asPathSet6 := config.AsPathSet{ + asPathSet6 := oc.AsPathSet{ AsPathSetName: "asset6", AsPathList: []string{".*_[0-9]+_65005"}, } - asPathSet7 := config.AsPathSet{ + asPathSet7 := oc.AsPathSet{ AsPathSetName: "asset7", AsPathList: []string{".*_5[0-9]+_[0-9]+"}, } - asPathSet8 := config.AsPathSet{ + asPathSet8 := oc.AsPathSet{ AsPathSetName: "asset8", AsPathList: []string{"6[0-9]+_6[0-9]+_5[0-9]+"}, } - asPathSet9 := config.AsPathSet{ + asPathSet9 := oc.AsPathSet{ AsPathSetName: "asset9", AsPathList: []string{"6[0-9]+__6[0-9]+"}, } m := make(map[string]DefinedSet) - for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3, + for _, s := range []oc.AsPathSet{asPathSet1, asPathSet2, asPathSet3, asPathSet4, asPathSet5, asPathSet6, asPathSet7, asPathSet8, asPathSet9} { a, _ := NewAsPathSet(s) m[s.AsPathSetName] = a } - createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCondition { - matchSet := config.MatchAsPathSet{} + createAspathC := func(name string, option oc.MatchSetOptionsType) *AsPathCondition { + matchSet := oc.MatchAsPathSet{} matchSet.AsPathSet = name matchSet.MatchSetOptions = option p, _ := NewAsPathCondition(matchSet) @@ -935,15 +935,15 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) { return p } - p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY) - p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createAspathC("asset7", config.MATCH_SET_OPTIONS_TYPE_ANY) - p8 := createAspathC("asset8", config.MATCH_SET_OPTIONS_TYPE_ANY) - p9 := createAspathC("asset9", config.MATCH_SET_OPTIONS_TYPE_ANY) + p1 := createAspathC("asset1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createAspathC("asset2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p4 := createAspathC("asset4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createAspathC("asset5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createAspathC("asset6", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p7 := createAspathC("asset7", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p8 := createAspathC("asset8", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p9 := createAspathC("asset9", oc.MATCH_SET_OPTIONS_TYPE_ANY) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -1016,13 +1016,13 @@ func TestAsPathCondition(t *testing.T) { } for k, v := range tests { - s, _ := NewAsPathSet(config.AsPathSet{ + s, _ := NewAsPathSet(oc.AsPathSet{ AsPathSetName: k, AsPathList: []string{k}, }) - c, _ := NewAsPathCondition(config.MatchAsPathSet{ + c, _ := NewAsPathCondition(oc.MatchAsPathSet{ AsPathSet: k, - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_TYPE_ANY, }) c.set = s for _, a := range v { @@ -1058,7 +1058,7 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) { path := ProcessMessage(updateMsg, peer, time.Now())[0] // create policy - asPathSet := config.AsPathSet{ + asPathSet := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{"65005$"}, } @@ -1066,10 +1066,10 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) { ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} - ds.BgpDefinedSets.AsPathSets = []config.AsPathSet{asPathSet} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} + ds.BgpDefinedSets.AsPathSets = []oc.AsPathSet{asPathSet} s := createStatement("statement1", "ps1", "ns1", false) s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1" @@ -1124,17 +1124,17 @@ func TestAs4PathConditionEvaluate(t *testing.T) { path2 := ProcessMessage(updateMsg2, peer, time.Now())[0] // create match condition - asPathSet1 := config.AsPathSet{ + asPathSet1 := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{fmt.Sprintf("^%d", createAs4Value("65001.1"))}, } - asPathSet2 := config.AsPathSet{ + asPathSet2 := oc.AsPathSet{ AsPathSetName: "asset2", AsPathList: []string{fmt.Sprintf("%d$", createAs4Value("65005.1"))}, } - asPathSet3 := config.AsPathSet{ + asPathSet3 := oc.AsPathSet{ AsPathSetName: "asset3", AsPathList: []string{ fmt.Sprintf("%d", createAs4Value("65004.1")), @@ -1142,21 +1142,21 @@ func TestAs4PathConditionEvaluate(t *testing.T) { }, } - asPathSet4 := config.AsPathSet{ + asPathSet4 := oc.AsPathSet{ AsPathSetName: "asset4", AsPathList: []string{ fmt.Sprintf("%d$", createAs4Value("65000.1")), }, } - asPathSet5 := config.AsPathSet{ + asPathSet5 := oc.AsPathSet{ AsPathSetName: "asset5", AsPathList: []string{ fmt.Sprintf("%d", createAs4Value("65010.1")), }, } - asPathSet6 := config.AsPathSet{ + asPathSet6 := oc.AsPathSet{ AsPathSetName: "asset6", AsPathList: []string{ fmt.Sprintf("%d$", createAs4Value("65010.1")), @@ -1164,14 +1164,14 @@ func TestAs4PathConditionEvaluate(t *testing.T) { } m := make(map[string]DefinedSet) - for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3, + for _, s := range []oc.AsPathSet{asPathSet1, asPathSet2, asPathSet3, asPathSet4, asPathSet5, asPathSet6} { a, _ := NewAsPathSet(s) m[s.AsPathSetName] = a } - createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCondition { - matchSet := config.MatchAsPathSet{} + createAspathC := func(name string, option oc.MatchSetOptionsType) *AsPathCondition { + matchSet := oc.MatchAsPathSet{} matchSet.AsPathSet = name matchSet.MatchSetOptions = option p, _ := NewAsPathCondition(matchSet) @@ -1181,15 +1181,15 @@ func TestAs4PathConditionEvaluate(t *testing.T) { return p } - p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY) - p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY) + p1 := createAspathC("asset1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createAspathC("asset2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p4 := createAspathC("asset4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createAspathC("asset5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createAspathC("asset6", oc.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ALL) - p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT) + p7 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ALL) + p8 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_INVERT) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -1230,72 +1230,72 @@ func TestMultipleAs4PathConditionEvaluate(t *testing.T) { path1 := ProcessMessage(updateMsg1, peer, time.Now())[0] // create match condition - asPathSet1 := config.AsPathSet{ + asPathSet1 := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{ fmt.Sprintf("^%d_%d", createAs4Value("65001.1"), createAs4Value("65000.1")), }, } - asPathSet2 := config.AsPathSet{ + asPathSet2 := oc.AsPathSet{ AsPathSetName: "asset2", AsPathList: []string{ fmt.Sprintf("%d_%d$", createAs4Value("65004.1"), createAs4Value("65005.1")), }, } - asPathSet3 := config.AsPathSet{ + asPathSet3 := oc.AsPathSet{ AsPathSetName: "asset3", AsPathList: []string{ fmt.Sprintf("%d_%d_%d", createAs4Value("65001.1"), createAs4Value("65000.1"), createAs4Value("54000.1")), }, } - asPathSet4 := config.AsPathSet{ + asPathSet4 := oc.AsPathSet{ AsPathSetName: "asset4", AsPathList: []string{ fmt.Sprintf("%d_%d_%d", createAs4Value("54000.1"), createAs4Value("65004.1"), createAs4Value("65005.1")), }, } - asPathSet5 := config.AsPathSet{ + asPathSet5 := oc.AsPathSet{ AsPathSetName: "asset5", AsPathList: []string{ fmt.Sprintf("^%d %d %d %d %d$", createAs4Value("65001.1"), createAs4Value("65000.1"), createAs4Value("54000.1"), createAs4Value("65004.1"), createAs4Value("65005.1")), }, } - asPathSet6 := config.AsPathSet{ + asPathSet6 := oc.AsPathSet{ AsPathSetName: "asset6", AsPathList: []string{ fmt.Sprintf(".*_[0-9]+_%d", createAs4Value("65005.1")), }, } - asPathSet7 := config.AsPathSet{ + asPathSet7 := oc.AsPathSet{ AsPathSetName: "asset7", AsPathList: []string{".*_3[0-9]+_[0-9]+"}, } - asPathSet8 := config.AsPathSet{ + asPathSet8 := oc.AsPathSet{ AsPathSetName: "asset8", AsPathList: []string{"4[0-9]+_4[0-9]+_3[0-9]+"}, } - asPathSet9 := config.AsPathSet{ + asPathSet9 := oc.AsPathSet{ AsPathSetName: "asset9", AsPathList: []string{"4[0-9]+__4[0-9]+"}, } m := make(map[string]DefinedSet) - for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3, + for _, s := range []oc.AsPathSet{asPathSet1, asPathSet2, asPathSet3, asPathSet4, asPathSet5, asPathSet6, asPathSet7, asPathSet8, asPathSet9} { a, _ := NewAsPathSet(s) m[s.AsPathSetName] = a } - createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCondition { - matchSet := config.MatchAsPathSet{} + createAspathC := func(name string, option oc.MatchSetOptionsType) *AsPathCondition { + matchSet := oc.MatchAsPathSet{} matchSet.AsPathSet = name matchSet.MatchSetOptions = option p, _ := NewAsPathCondition(matchSet) @@ -1305,15 +1305,15 @@ func TestMultipleAs4PathConditionEvaluate(t *testing.T) { return p } - p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY) - p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createAspathC("asset7", config.MATCH_SET_OPTIONS_TYPE_ANY) - p8 := createAspathC("asset8", config.MATCH_SET_OPTIONS_TYPE_ANY) - p9 := createAspathC("asset9", config.MATCH_SET_OPTIONS_TYPE_ANY) + p1 := createAspathC("asset1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createAspathC("asset2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p4 := createAspathC("asset4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createAspathC("asset5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createAspathC("asset6", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p7 := createAspathC("asset7", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p8 := createAspathC("asset8", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p9 := createAspathC("asset9", oc.MATCH_SET_OPTIONS_TYPE_ANY) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -1358,7 +1358,7 @@ func TestAs4PathConditionWithOtherCondition(t *testing.T) { path := ProcessMessage(updateMsg, peer, time.Now())[0] // create policy - asPathSet := config.AsPathSet{ + asPathSet := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{fmt.Sprintf("%d$", createAs4Value("65005.1"))}, } @@ -1366,10 +1366,10 @@ func TestAs4PathConditionWithOtherCondition(t *testing.T) { ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} - ds.BgpDefinedSets.AsPathSets = []config.AsPathSet{asPathSet} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} + ds.BgpDefinedSets.AsPathSets = []oc.AsPathSet{asPathSet} s := createStatement("statement1", "ps1", "ns1", false) s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1" @@ -1417,50 +1417,50 @@ func TestAs4PathConditionEvaluateMixedWith2byteAS(t *testing.T) { path1 := ProcessMessage(updateMsg1, peer, time.Now())[0] // create match condition - asPathSet1 := config.AsPathSet{ + asPathSet1 := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{fmt.Sprintf("^%d", createAs4Value("65001.1"))}, } - asPathSet2 := config.AsPathSet{ + asPathSet2 := oc.AsPathSet{ AsPathSetName: "asset2", AsPathList: []string{"4000$"}, } - asPathSet3 := config.AsPathSet{ + asPathSet3 := oc.AsPathSet{ AsPathSetName: "asset3", AsPathList: []string{fmt.Sprintf("%d", createAs4Value("65004.1")), "4000$"}, } - asPathSet4 := config.AsPathSet{ + asPathSet4 := oc.AsPathSet{ AsPathSetName: "asset4", AsPathList: []string{fmt.Sprintf("%d_%d_%d", createAs4Value("54000.1"), 100, 5000)}, } - asPathSet5 := config.AsPathSet{ + asPathSet5 := oc.AsPathSet{ AsPathSetName: "asset5", AsPathList: []string{".*_[0-9]+_100"}, } - asPathSet6 := config.AsPathSet{ + asPathSet6 := oc.AsPathSet{ AsPathSetName: "asset6", AsPathList: []string{".*_3[0-9]+_[0]+"}, } - asPathSet7 := config.AsPathSet{ + asPathSet7 := oc.AsPathSet{ AsPathSetName: "asset7", AsPathList: []string{".*_3[0-9]+_[1]+"}, } m := make(map[string]DefinedSet) - for _, s := range []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3, + for _, s := range []oc.AsPathSet{asPathSet1, asPathSet2, asPathSet3, asPathSet4, asPathSet5, asPathSet6, asPathSet7} { a, _ := NewAsPathSet(s) m[s.AsPathSetName] = a } - createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCondition { - matchSet := config.MatchAsPathSet{} + createAspathC := func(name string, option oc.MatchSetOptionsType) *AsPathCondition { + matchSet := oc.MatchAsPathSet{} matchSet.AsPathSet = name matchSet.MatchSetOptions = option p, _ := NewAsPathCondition(matchSet) @@ -1470,13 +1470,13 @@ func TestAs4PathConditionEvaluateMixedWith2byteAS(t *testing.T) { return p } - p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ALL) - p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createAspathC("asset7", config.MATCH_SET_OPTIONS_TYPE_ANY) + p1 := createAspathC("asset1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createAspathC("asset2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createAspathC("asset3", oc.MATCH_SET_OPTIONS_TYPE_ALL) + p4 := createAspathC("asset4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createAspathC("asset5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createAspathC("asset6", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p7 := createAspathC("asset7", oc.MATCH_SET_OPTIONS_TYPE_ANY) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -1530,47 +1530,47 @@ func TestCommunityConditionEvaluate(t *testing.T) { path2 := ProcessMessage(updateMsg2, peer, time.Now())[0] // create match condition - comSet1 := config.CommunitySet{ + comSet1 := oc.CommunitySet{ CommunitySetName: "comset1", CommunityList: []string{"65001:10", "65001:50", "65001:100"}, } - comSet2 := config.CommunitySet{ + comSet2 := oc.CommunitySet{ CommunitySetName: "comset2", CommunityList: []string{"65001:200"}, } - comSet3 := config.CommunitySet{ + comSet3 := oc.CommunitySet{ CommunitySetName: "comset3", CommunityList: []string{"4259905936"}, } - comSet4 := config.CommunitySet{ + comSet4 := oc.CommunitySet{ CommunitySetName: "comset4", CommunityList: []string{"^[0-9]*:300$"}, } - comSet5 := config.CommunitySet{ + comSet5 := oc.CommunitySet{ CommunitySetName: "comset5", CommunityList: []string{"INTERNET"}, } - comSet6 := config.CommunitySet{ + comSet6 := oc.CommunitySet{ CommunitySetName: "comset6", CommunityList: []string{"NO_EXPORT"}, } - comSet7 := config.CommunitySet{ + comSet7 := oc.CommunitySet{ CommunitySetName: "comset7", CommunityList: []string{"NO_ADVERTISE"}, } - comSet8 := config.CommunitySet{ + comSet8 := oc.CommunitySet{ CommunitySetName: "comset8", CommunityList: []string{"NO_EXPORT_SUBCONFED"}, } - comSet9 := config.CommunitySet{ + comSet9 := oc.CommunitySet{ CommunitySetName: "comset9", CommunityList: []string{ "65001:\\d+", @@ -1578,7 +1578,7 @@ func TestCommunityConditionEvaluate(t *testing.T) { }, } - comSet10 := config.CommunitySet{ + comSet10 := oc.CommunitySet{ CommunitySetName: "comset10", CommunityList: []string{ "65001:1", @@ -1589,14 +1589,14 @@ func TestCommunityConditionEvaluate(t *testing.T) { m := make(map[string]DefinedSet) - for _, c := range []config.CommunitySet{comSet1, comSet2, comSet3, + for _, c := range []oc.CommunitySet{comSet1, comSet2, comSet3, comSet4, comSet5, comSet6, comSet7, comSet8, comSet9, comSet10} { s, _ := NewCommunitySet(c) m[c.CommunitySetName] = s } - createCommunityC := func(name string, option config.MatchSetOptionsType) *CommunityCondition { - matchSet := config.MatchCommunitySet{} + createCommunityC := func(name string, option oc.MatchSetOptionsType) *CommunityCondition { + matchSet := oc.MatchCommunitySet{} matchSet.CommunitySet = name matchSet.MatchSetOptions = option c, _ := NewCommunityCondition(matchSet) @@ -1607,20 +1607,20 @@ func TestCommunityConditionEvaluate(t *testing.T) { } // ANY case - p1 := createCommunityC("comset1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createCommunityC("comset2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createCommunityC("comset3", config.MATCH_SET_OPTIONS_TYPE_ANY) - p4 := createCommunityC("comset4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createCommunityC("comset5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createCommunityC("comset6", config.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createCommunityC("comset7", config.MATCH_SET_OPTIONS_TYPE_ANY) - p8 := createCommunityC("comset8", config.MATCH_SET_OPTIONS_TYPE_ANY) + p1 := createCommunityC("comset1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createCommunityC("comset2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createCommunityC("comset3", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p4 := createCommunityC("comset4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createCommunityC("comset5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createCommunityC("comset6", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p7 := createCommunityC("comset7", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p8 := createCommunityC("comset8", oc.MATCH_SET_OPTIONS_TYPE_ANY) // ALL case - p9 := createCommunityC("comset9", config.MATCH_SET_OPTIONS_TYPE_ALL) + p9 := createCommunityC("comset9", oc.MATCH_SET_OPTIONS_TYPE_ALL) // INVERT case - p10 := createCommunityC("comset10", config.MATCH_SET_OPTIONS_TYPE_INVERT) + p10 := createCommunityC("comset10", oc.MATCH_SET_OPTIONS_TYPE_INVERT) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -1665,17 +1665,17 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) { path := ProcessMessage(updateMsg, peer, time.Now())[0] // create policy - asPathSet := config.AsPathSet{ + asPathSet := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{"65005$"}, } - comSet1 := config.CommunitySet{ + comSet1 := oc.CommunitySet{ CommunitySetName: "comset1", CommunityList: []string{"65001:100", "65001:200", "65001:300"}, } - comSet2 := config.CommunitySet{ + comSet2 := oc.CommunitySet{ CommunitySetName: "comset2", CommunityList: []string{"65050:\\d+"}, } @@ -1683,11 +1683,11 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} - ds.BgpDefinedSets.AsPathSets = []config.AsPathSet{asPathSet} - ds.BgpDefinedSets.CommunitySets = []config.CommunitySet{comSet1, comSet2} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} + ds.BgpDefinedSets.AsPathSets = []oc.AsPathSet{asPathSet} + ds.BgpDefinedSets.CommunitySets = []oc.CommunitySet{comSet1, comSet2} s1 := createStatement("statement1", "ps1", "ns1", false) s1.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1" @@ -1734,9 +1734,9 @@ func TestPolicyMatchAndAddCommunities(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} community := "65000:100" @@ -1778,9 +1778,9 @@ func TestPolicyMatchAndReplaceCommunities(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} community := "65000:100" @@ -1825,9 +1825,9 @@ func TestPolicyMatchAndRemoveCommunities(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1) @@ -1871,9 +1871,9 @@ func TestPolicyMatchAndRemoveCommunitiesRegexp(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", ".*:100") @@ -1917,9 +1917,9 @@ func TestPolicyMatchAndRemoveCommunitiesRegexp2(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", "^(0|45686):[0-9]+") @@ -1961,9 +1961,9 @@ func TestPolicyMatchAndClearCommunities(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) // action NULL is obsolate @@ -2070,64 +2070,64 @@ func TestExtCommunityConditionEvaluate(t *testing.T) { } // create match condition - ecomSet1 := config.ExtCommunitySet{ + ecomSet1 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet1", ExtCommunityList: []string{"RT:65001:200"}, } - ecomSet2 := config.ExtCommunitySet{ + ecomSet2 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet2", ExtCommunityList: []string{"RT:10.0.0.1:300"}, } - ecomSet3 := config.ExtCommunitySet{ + ecomSet3 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet3", ExtCommunityList: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030000))}, } - ecomSet4 := config.ExtCommunitySet{ + ecomSet4 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet4", ExtCommunityList: []string{"RT:65002:200"}, } - ecomSet5 := config.ExtCommunitySet{ + ecomSet5 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet5", ExtCommunityList: []string{"RT:10.0.0.2:300"}, } - ecomSet6 := config.ExtCommunitySet{ + ecomSet6 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet6", ExtCommunityList: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030001))}, } - ecomSet7 := config.ExtCommunitySet{ + ecomSet7 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet7", ExtCommunityList: []string{"SoO:65010:300"}, } - ecomSet8 := config.ExtCommunitySet{ + ecomSet8 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet8", ExtCommunityList: []string{"SoO:10.0.10.10:[0-9]+"}, } - ecomSet9 := config.ExtCommunitySet{ + ecomSet9 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet9", ExtCommunityList: []string{"RT:[0-9]+:[0-9]+"}, } - ecomSet10 := config.ExtCommunitySet{ + ecomSet10 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet10", ExtCommunityList: []string{"RT:.+:\\d00", "SoO:.+:\\d00"}, } - ecomSet11 := config.ExtCommunitySet{ + ecomSet11 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet11", ExtCommunityList: []string{"RT:65001:2", "SoO:11.0.10.10:[0-9]+"}, } - ecomSet12 := config.ExtCommunitySet{ + ecomSet12 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet12", ExtCommunityList: []string{"LB:65001:125000"}, } m := make(map[string]DefinedSet) - for _, c := range []config.ExtCommunitySet{ecomSet1, ecomSet2, ecomSet3, ecomSet4, ecomSet5, ecomSet6, ecomSet7, + for _, c := range []oc.ExtCommunitySet{ecomSet1, ecomSet2, ecomSet3, ecomSet4, ecomSet5, ecomSet6, ecomSet7, ecomSet8, ecomSet9, ecomSet10, ecomSet11, ecomSet12} { s, _ := NewExtCommunitySet(c) m[s.Name()] = s } - createExtCommunityC := func(name string, option config.MatchSetOptionsType) *ExtCommunityCondition { - matchSet := config.MatchExtCommunitySet{} + createExtCommunityC := func(name string, option oc.MatchSetOptionsType) *ExtCommunityCondition { + matchSet := oc.MatchExtCommunitySet{} matchSet.ExtCommunitySet = name matchSet.MatchSetOptions = option c, _ := NewExtCommunityCondition(matchSet) @@ -2138,21 +2138,21 @@ func TestExtCommunityConditionEvaluate(t *testing.T) { return c } - p1 := createExtCommunityC("ecomSet1", config.MATCH_SET_OPTIONS_TYPE_ANY) - p2 := createExtCommunityC("ecomSet2", config.MATCH_SET_OPTIONS_TYPE_ANY) - p3 := createExtCommunityC("ecomSet3", config.MATCH_SET_OPTIONS_TYPE_ANY) - p4 := createExtCommunityC("ecomSet4", config.MATCH_SET_OPTIONS_TYPE_ANY) - p5 := createExtCommunityC("ecomSet5", config.MATCH_SET_OPTIONS_TYPE_ANY) - p6 := createExtCommunityC("ecomSet6", config.MATCH_SET_OPTIONS_TYPE_ANY) - p7 := createExtCommunityC("ecomSet7", config.MATCH_SET_OPTIONS_TYPE_ANY) - p8 := createExtCommunityC("ecomSet8", config.MATCH_SET_OPTIONS_TYPE_ANY) - p9 := createExtCommunityC("ecomSet9", config.MATCH_SET_OPTIONS_TYPE_ANY) + p1 := createExtCommunityC("ecomSet1", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p2 := createExtCommunityC("ecomSet2", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p3 := createExtCommunityC("ecomSet3", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p4 := createExtCommunityC("ecomSet4", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p5 := createExtCommunityC("ecomSet5", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p6 := createExtCommunityC("ecomSet6", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p7 := createExtCommunityC("ecomSet7", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p8 := createExtCommunityC("ecomSet8", oc.MATCH_SET_OPTIONS_TYPE_ANY) + p9 := createExtCommunityC("ecomSet9", oc.MATCH_SET_OPTIONS_TYPE_ANY) // ALL case - p10 := createExtCommunityC("ecomSet10", config.MATCH_SET_OPTIONS_TYPE_ALL) + p10 := createExtCommunityC("ecomSet10", oc.MATCH_SET_OPTIONS_TYPE_ALL) // INVERT case - p11 := createExtCommunityC("ecomSet11", config.MATCH_SET_OPTIONS_TYPE_INVERT) + p11 := createExtCommunityC("ecomSet11", oc.MATCH_SET_OPTIONS_TYPE_INVERT) // test assert.Equal(t, true, p1.Evaluate(path1, nil)) @@ -2247,16 +2247,16 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) { path := ProcessMessage(updateMsg, peer, time.Now())[0] // create policy - asPathSet := config.AsPathSet{ + asPathSet := oc.AsPathSet{ AsPathSetName: "asset1", AsPathList: []string{"65005$"}, } - ecomSet1 := config.ExtCommunitySet{ + ecomSet1 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet1", ExtCommunityList: []string{"RT:65001:201"}, } - ecomSet2 := config.ExtCommunitySet{ + ecomSet2 := oc.ExtCommunitySet{ ExtCommunitySetName: "ecomSet2", ExtCommunityList: []string{"RT:[0-9]+:[0-9]+"}, } @@ -2264,11 +2264,11 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) { ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24") ns := createNeighborSet("ns1", "10.2.1.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} - ds.BgpDefinedSets.AsPathSets = []config.AsPathSet{asPathSet} - ds.BgpDefinedSets.ExtCommunitySets = []config.ExtCommunitySet{ecomSet1, ecomSet2} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} + ds.BgpDefinedSets.AsPathSets = []oc.AsPathSet{asPathSet} + ds.BgpDefinedSets.ExtCommunitySets = []oc.ExtCommunitySet{ecomSet1, ecomSet2} s1 := createStatement("statement1", "ps1", "ns1", false) s1.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1" @@ -2315,13 +2315,13 @@ func TestPolicyMatchAndReplaceMed(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} m := "200" s := createStatement("statement1", "ps1", "ns1", true) - s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) + s.Actions.BgpActions.SetMed = oc.BgpSetMedType(m) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -2359,14 +2359,14 @@ func TestPolicyMatchAndAddingMed(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} m := "+200" ma := "300" s := createStatement("statement1", "ps1", "ns1", true) - s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) + s.Actions.BgpActions.SetMed = oc.BgpSetMedType(m) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -2403,15 +2403,15 @@ func TestPolicyMatchAndAddingMedOverFlow(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} m := fmt.Sprintf("+%d", uint32(math.MaxUint32)) ma := "1" s := createStatement("statement1", "ps1", "ns1", true) - s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) + s.Actions.BgpActions.SetMed = oc.BgpSetMedType(m) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -2449,15 +2449,15 @@ func TestPolicyMatchAndSubtractMed(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} m := "-50" ma := "50" s := createStatement("statement1", "ps1", "ns1", true) - s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) + s.Actions.BgpActions.SetMed = oc.BgpSetMedType(m) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -2495,15 +2495,15 @@ func TestPolicyMatchAndSubtractMedUnderFlow(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} m := "-101" ma := "100" s := createStatement("statement1", "ps1", "ns1", true) - s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) + s.Actions.BgpActions.SetMed = oc.BgpSetMedType(m) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -2540,13 +2540,13 @@ func TestPolicyMatchWhenPathHaveNotMed(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} m := "-50" s := createStatement("statement1", "ps1", "ns1", true) - s.Actions.BgpActions.SetMed = config.BgpSetMedType(m) + s.Actions.BgpActions.SetMed = oc.BgpSetMedType(m) pd := createPolicyDefinition("pd1", s) pl := createRoutingPolicy(ds, pd) @@ -2588,9 +2588,9 @@ func TestPolicyAsPathPrepend(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetAsPathPrepend.As = "65002" @@ -2632,9 +2632,9 @@ func TestPolicyAsPathPrependLastAs(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetAsPathPrepend.As = "last-as" @@ -2682,9 +2682,9 @@ func TestPolicyAs4PathPrepend(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetAsPathPrepend.As = fmt.Sprintf("%d", createAs4Value("65002.1")) @@ -2739,9 +2739,9 @@ func TestPolicyAs4PathPrependLastAs(t *testing.T) { ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24") ns := createNeighborSet("ns1", "10.0.0.1") - ds := config.DefinedSets{} - ds.PrefixSets = []config.PrefixSet{ps} - ds.NeighborSets = []config.NeighborSet{ns} + ds := oc.DefinedSets{} + ds.PrefixSets = []oc.PrefixSet{ps} + ds.NeighborSets = []oc.NeighborSet{ns} s := createStatement("statement1", "ps1", "ns1", true) s.Actions.BgpActions.SetAsPathPrepend.As = "last-as" @@ -2833,23 +2833,23 @@ func TestLocalPrefAction(t *testing.T) { assert.Equal(t, int(lp.Value), int(10)) } -func createStatement(name, psname, nsname string, accept bool) config.Statement { - c := config.Conditions{ - MatchPrefixSet: config.MatchPrefixSet{ +func createStatement(name, psname, nsname string, accept bool) oc.Statement { + c := oc.Conditions{ + MatchPrefixSet: oc.MatchPrefixSet{ PrefixSet: psname, }, - MatchNeighborSet: config.MatchNeighborSet{ + MatchNeighborSet: oc.MatchNeighborSet{ NeighborSet: nsname, }, } - rd := config.ROUTE_DISPOSITION_REJECT_ROUTE + rd := oc.ROUTE_DISPOSITION_REJECT_ROUTE if accept { - rd = config.ROUTE_DISPOSITION_ACCEPT_ROUTE + rd = oc.ROUTE_DISPOSITION_ACCEPT_ROUTE } - a := config.Actions{ + a := oc.Actions{ RouteDisposition: rd, } - s := config.Statement{ + s := oc.Statement{ Name: name, Conditions: c, Actions: a, @@ -2857,10 +2857,10 @@ func createStatement(name, psname, nsname string, accept bool) config.Statement return s } -func createSetCommunity(operation string, community ...string) config.SetCommunity { +func createSetCommunity(operation string, community ...string) oc.SetCommunity { - s := config.SetCommunity{ - SetCommunityMethod: config.SetCommunityMethod{ + s := oc.SetCommunity{ + SetCommunityMethod: oc.SetCommunityMethod{ CommunitiesList: community, }, Options: operation, @@ -2875,26 +2875,26 @@ func stringToCommunityValue(comStr string) uint32 { return uint32(asn<<16 | val) } -func createPolicyDefinition(defName string, stmt ...config.Statement) config.PolicyDefinition { - pd := config.PolicyDefinition{ +func createPolicyDefinition(defName string, stmt ...oc.Statement) oc.PolicyDefinition { + pd := oc.PolicyDefinition{ Name: defName, - Statements: []config.Statement(stmt), + Statements: []oc.Statement(stmt), } return pd } -func createRoutingPolicy(ds config.DefinedSets, pd ...config.PolicyDefinition) config.RoutingPolicy { - pl := config.RoutingPolicy{ +func createRoutingPolicy(ds oc.DefinedSets, pd ...oc.PolicyDefinition) oc.RoutingPolicy { + pl := oc.RoutingPolicy{ DefinedSets: ds, - PolicyDefinitions: []config.PolicyDefinition(pd), + PolicyDefinitions: []oc.PolicyDefinition(pd), } return pl } -func createPrefixSet(name string, prefix string, maskLength string) config.PrefixSet { - ps := config.PrefixSet{ +func createPrefixSet(name string, prefix string, maskLength string) oc.PrefixSet { + ps := oc.PrefixSet{ PrefixSetName: name, - PrefixList: []config.Prefix{ + PrefixList: []oc.Prefix{ { IpPrefix: prefix, MasklengthRange: maskLength, @@ -2903,8 +2903,8 @@ func createPrefixSet(name string, prefix string, maskLength string) config.Prefi return ps } -func createNeighborSet(name string, addr string) config.NeighborSet { - ns := config.NeighborSet{ +func createNeighborSet(name string, addr string) oc.NeighborSet { + ns := oc.NeighborSet{ NeighborSetName: name, NeighborInfoList: []string{addr}, } @@ -2920,48 +2920,48 @@ func createAs4Value(s string) uint32 { func TestPrefixSetOperation(t *testing.T) { // tryp to create prefixset with multiple families - p1 := config.Prefix{ + p1 := oc.Prefix{ IpPrefix: "0.0.0.0/0", MasklengthRange: "0..7", } - p2 := config.Prefix{ + p2 := oc.Prefix{ IpPrefix: "0::/25", MasklengthRange: "25..128", } - _, err := NewPrefixSet(config.PrefixSet{ + _, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1, p2}, + PrefixList: []oc.Prefix{p1, p2}, }) assert.NotNil(t, err) - m1, _ := NewPrefixSet(config.PrefixSet{ + m1, _ := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1}, + PrefixList: []oc.Prefix{p1}, }) - m2, err := NewPrefixSet(config.PrefixSet{PrefixSetName: "ps2"}) + m2, err := NewPrefixSet(oc.PrefixSet{PrefixSetName: "ps2"}) assert.Nil(t, err) err = m1.Append(m2) assert.Nil(t, err) err = m2.Append(m1) assert.Nil(t, err) assert.Equal(t, bgp.RF_IPv4_UC, m2.family) - p3, _ := NewPrefix(config.Prefix{IpPrefix: "10.10.0.0/24", MasklengthRange: ""}) - p4, _ := NewPrefix(config.Prefix{IpPrefix: "0::/25", MasklengthRange: ""}) + p3, _ := NewPrefix(oc.Prefix{IpPrefix: "10.10.0.0/24", MasklengthRange: ""}) + p4, _ := NewPrefix(oc.Prefix{IpPrefix: "0::/25", MasklengthRange: ""}) _, err = NewPrefixSetFromApiStruct("ps3", []*Prefix{p3, p4}) assert.NotNil(t, err) } func TestPrefixSetMatch(t *testing.T) { - p1 := config.Prefix{ + p1 := oc.Prefix{ IpPrefix: "0.0.0.0/0", MasklengthRange: "0..7", } - p2 := config.Prefix{ + p2 := oc.Prefix{ IpPrefix: "0.0.0.0/0", MasklengthRange: "25..32", } - ps, err := NewPrefixSet(config.PrefixSet{ + ps, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1, p2}, + PrefixList: []oc.Prefix{p1, p2}, }) assert.Nil(t, err) m := &PrefixCondition{ @@ -2980,13 +2980,13 @@ func TestPrefixSetMatch(t *testing.T) { path = NewPath(nil, bgp.NewIPAddrPrefix(30, "0.0.0.0"), false, []bgp.PathAttributeInterface{}, time.Now(), false) assert.True(t, m.Evaluate(path, nil)) - p3 := config.Prefix{ + p3 := oc.Prefix{ IpPrefix: "0.0.0.0/0", MasklengthRange: "9..10", } - ps2, err := NewPrefixSet(config.PrefixSet{ + ps2, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps2", - PrefixList: []config.Prefix{p3}, + PrefixList: []oc.Prefix{p3}, }) assert.Nil(t, err) err = ps.Append(ps2) @@ -2995,9 +2995,9 @@ func TestPrefixSetMatch(t *testing.T) { path = NewPath(nil, bgp.NewIPAddrPrefix(10, "0.0.0.0"), false, []bgp.PathAttributeInterface{}, time.Now(), false) assert.True(t, m.Evaluate(path, nil)) - ps3, err := NewPrefixSet(config.PrefixSet{ + ps3, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps3", - PrefixList: []config.Prefix{p1}, + PrefixList: []oc.Prefix{p1}, }) assert.Nil(t, err) err = ps.Remove(ps3) @@ -3008,13 +3008,13 @@ func TestPrefixSetMatch(t *testing.T) { } func TestPrefixSetMatchV4withV6Prefix(t *testing.T) { - p1 := config.Prefix{ + p1 := oc.Prefix{ IpPrefix: "c000::/3", MasklengthRange: "3..128", } - ps, err := NewPrefixSet(config.PrefixSet{ + ps, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1}, + PrefixList: []oc.Prefix{p1}, }) assert.Nil(t, err) m := &PrefixCondition{ @@ -3026,13 +3026,13 @@ func TestPrefixSetMatchV4withV6Prefix(t *testing.T) { } func TestPrefixSetMatchV6LabeledwithV6Prefix(t *testing.T) { - p1 := config.Prefix{ + p1 := oc.Prefix{ IpPrefix: "2806:106e:19::/48", MasklengthRange: "48..48", } - ps, err := NewPrefixSet(config.PrefixSet{ + ps, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1}, + PrefixList: []oc.Prefix{p1}, }) assert.Nil(t, err) m := &PrefixCondition{ @@ -3051,13 +3051,13 @@ func TestPrefixSetMatchV6LabeledwithV6Prefix(t *testing.T) { } func TestPrefixSetMatchVPNV4Prefix(t *testing.T) { - p1 := config.Prefix{ + p1 := oc.Prefix{ IpPrefix: "10.10.10.0/24", MasklengthRange: "24..32", } - ps, err := NewPrefixSet(config.PrefixSet{ + ps, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1}, + PrefixList: []oc.Prefix{p1}, }) assert.Nil(t, err) m := &PrefixCondition{ @@ -3081,13 +3081,13 @@ func TestPrefixSetMatchVPNV4Prefix(t *testing.T) { } func TestPrefixSetMatchVPNV6Prefix(t *testing.T) { - p1 := config.Prefix{ + p1 := oc.Prefix{ IpPrefix: "2001:123:123:1::/64", MasklengthRange: "64..128", } - ps, err := NewPrefixSet(config.PrefixSet{ + ps, err := NewPrefixSet(oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{p1}, + PrefixList: []oc.Prefix{p1}, }) assert.Nil(t, err) m := &PrefixCondition{ @@ -3117,7 +3117,7 @@ func TestLargeCommunityMatchAction(t *testing.T) { } p := NewPath(nil, nil, false, []bgp.PathAttributeInterface{bgp.NewPathAttributeLargeCommunities(coms)}, time.Time{}, false) - c := config.LargeCommunitySet{ + c := oc.LargeCommunitySet{ LargeCommunitySetName: "l0", LargeCommunityList: []string{ "100:100:100", @@ -3128,7 +3128,7 @@ func TestLargeCommunityMatchAction(t *testing.T) { set, err := NewLargeCommunitySet(c) assert.Equal(t, err, nil) - m, err := NewLargeCommunityCondition(config.MatchLargeCommunitySet{ + m, err := NewLargeCommunityCondition(oc.MatchLargeCommunitySet{ LargeCommunitySet: "l0", }) assert.Equal(t, err, nil) @@ -3136,43 +3136,43 @@ func TestLargeCommunityMatchAction(t *testing.T) { assert.Equal(t, m.Evaluate(p, nil), true) - a, err := NewLargeCommunityAction(config.SetLargeCommunity{ - SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + a, err := NewLargeCommunityAction(oc.SetLargeCommunity{ + SetLargeCommunityMethod: oc.SetLargeCommunityMethod{ CommunitiesList: []string{"100:100:100"}, }, - Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + Options: oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, }) assert.Equal(t, err, nil) p, _ = a.Apply(p, nil) assert.Equal(t, m.Evaluate(p, nil), false) - a, err = NewLargeCommunityAction(config.SetLargeCommunity{ - SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + a, err = NewLargeCommunityAction(oc.SetLargeCommunity{ + SetLargeCommunityMethod: oc.SetLargeCommunityMethod{ CommunitiesList: []string{ "100:300:100", "200:100:100", }, }, - Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD, + Options: oc.BGP_SET_COMMUNITY_OPTION_TYPE_ADD, }) assert.Equal(t, err, nil) p, _ = a.Apply(p, nil) assert.Equal(t, m.Evaluate(p, nil), true) - a, err = NewLargeCommunityAction(config.SetLargeCommunity{ - SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + a, err = NewLargeCommunityAction(oc.SetLargeCommunity{ + SetLargeCommunityMethod: oc.SetLargeCommunityMethod{ CommunitiesList: []string{"^100:"}, }, - Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + Options: oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, }) assert.Equal(t, err, nil) p, _ = a.Apply(p, nil) assert.Equal(t, m.Evaluate(p, nil), false) - c = config.LargeCommunitySet{ + c = oc.LargeCommunitySet{ LargeCommunitySetName: "l1", LargeCommunityList: []string{ "200:", @@ -3182,7 +3182,7 @@ func TestLargeCommunityMatchAction(t *testing.T) { set, err = NewLargeCommunitySet(c) assert.Equal(t, err, nil) - m, err = NewLargeCommunityCondition(config.MatchLargeCommunitySet{ + m, err = NewLargeCommunityCondition(oc.MatchLargeCommunitySet{ LargeCommunitySet: "l1", }) assert.Equal(t, err, nil) @@ -3198,14 +3198,14 @@ func TestLargeCommunitiesMatchClearAction(t *testing.T) { } p := NewPath(nil, nil, false, []bgp.PathAttributeInterface{bgp.NewPathAttributeLargeCommunities(coms)}, time.Time{}, false) - a, err := NewLargeCommunityAction(config.SetLargeCommunity{ - SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + a, err := NewLargeCommunityAction(oc.SetLargeCommunity{ + SetLargeCommunityMethod: oc.SetLargeCommunityMethod{ CommunitiesList: []string{ "100:100:100", "100:200:200", }, }, - Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + Options: oc.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, }) assert.Equal(t, err, nil) @@ -3216,7 +3216,7 @@ func TestLargeCommunitiesMatchClearAction(t *testing.T) { } func TestAfiSafiInMatchPath(t *testing.T) { - condition, err := NewAfiSafiInCondition([]config.AfiSafiType{config.AFI_SAFI_TYPE_L3VPN_IPV4_UNICAST, config.AFI_SAFI_TYPE_L3VPN_IPV6_UNICAST}) + condition, err := NewAfiSafiInCondition([]oc.AfiSafiType{oc.AFI_SAFI_TYPE_L3VPN_IPV4_UNICAST, oc.AFI_SAFI_TYPE_L3VPN_IPV6_UNICAST}) require.NoError(t, err) rtExtCom, err := bgp.ParseExtendedCommunity(bgp.EC_SUBTYPE_ROUTE_TARGET, "100:100") @@ -3252,20 +3252,20 @@ func TestAfiSafiInMatchPath(t *testing.T) { func TestMultipleStatementPolicy(t *testing.T) { r := NewRoutingPolicy(logger) - rp := config.RoutingPolicy{ - PolicyDefinitions: []config.PolicyDefinition{{ + rp := oc.RoutingPolicy{ + PolicyDefinitions: []oc.PolicyDefinition{{ Name: "p1", - Statements: []config.Statement{ + Statements: []oc.Statement{ { - Actions: config.Actions{ - BgpActions: config.BgpActions{ + Actions: oc.Actions{ + BgpActions: oc.BgpActions{ SetMed: "+100", }, }, }, { - Actions: config.Actions{ - BgpActions: config.BgpActions{ + Actions: oc.Actions{ + BgpActions: oc.BgpActions{ SetLocalPref: 100, }, }, diff --git a/internal/pkg/table/roa.go b/internal/pkg/table/roa.go index d7d25944e..17b61d5d4 100644 --- a/internal/pkg/table/roa.go +++ b/internal/pkg/table/roa.go @@ -20,7 +20,7 @@ import ( "sort" "github.com/k-sone/critbitgo" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -189,7 +189,7 @@ func (rt *ROATable) Validate(path *Path) *Validation { var as uint32 validation := &Validation{ - Status: config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND, + Status: oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND, Reason: RPKI_VALIDATION_REASON_TYPE_NONE, Matched: make([]*ROA, 0), UnmatchedLength: make([]*ROA, 0), @@ -235,16 +235,16 @@ func (rt *ROATable) Validate(path *Path) *Validation { }) if len(validation.Matched) != 0 { - validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_VALID + validation.Status = oc.RPKI_VALIDATION_RESULT_TYPE_VALID validation.Reason = RPKI_VALIDATION_REASON_TYPE_NONE } else if len(validation.UnmatchedAs) != 0 { - validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_INVALID + validation.Status = oc.RPKI_VALIDATION_RESULT_TYPE_INVALID validation.Reason = RPKI_VALIDATION_REASON_TYPE_AS } else if len(validation.UnmatchedLength) != 0 { - validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_INVALID + validation.Status = oc.RPKI_VALIDATION_RESULT_TYPE_INVALID validation.Reason = RPKI_VALIDATION_REASON_TYPE_LENGTH } else { - validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND + validation.Status = oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND validation.Reason = RPKI_VALIDATION_REASON_TYPE_NONE } diff --git a/internal/pkg/table/roa_test.go b/internal/pkg/table/roa_test.go index 8b9f05dce..c2625290b 100644 --- a/internal/pkg/table/roa_test.go +++ b/internal/pkg/table/roa_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/stretchr/testify/assert" ) @@ -38,7 +38,7 @@ func strToASParam(str string) *bgp.PathAttributeAsPath { return bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(atype, as)}) } -func validateOne(rt *ROATable, cidr, aspathStr string) config.RpkiValidationResultType { +func validateOne(rt *ROATable, cidr, aspathStr string) oc.RpkiValidationResultType { var nlri bgp.AddrPrefixInterface ip, r, _ := net.ParseCIDR(cidr) length, _ := r.Mask.Size() @@ -61,22 +61,22 @@ func TestValidate0(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("192.168.0.0").To4(), 24, 24, 200, "")) r := validateOne(table, "192.168.0.0/24", "100") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "192.168.0.0/24", "100 200") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "192.168.0.0/24", "300") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) r = validateOne(table, "192.168.0.0/25", "100") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "192.168.0.0/25", "200") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) r = validateOne(table, "192.168.0.0/25", "300") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) } func TestValidate1(t *testing.T) { @@ -86,10 +86,10 @@ func TestValidate1(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, "")) r := validateOne(table, "10.0.0.0/16", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "10.0.0.0/16", "65001") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) } func TestValidate2(t *testing.T) { @@ -97,13 +97,13 @@ func TestValidate2(t *testing.T) { table := NewROATable(logger) - var r config.RpkiValidationResultType + var r oc.RpkiValidationResultType r = validateOne(table, "10.0.0.0/16", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) r = validateOne(table, "10.0.0.0/16", "65001") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) } func TestValidate3(t *testing.T) { @@ -113,16 +113,16 @@ func TestValidate3(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, "")) r := validateOne(table, "10.0.0.0/8", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) r = validateOne(table, "10.0.0.0/17", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) table = NewROATable(logger) table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, "")) r = validateOne(table, "10.0.0.0/17", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) } func TestValidate4(t *testing.T) { @@ -133,10 +133,10 @@ func TestValidate4(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65001, "")) r := validateOne(table, "10.0.0.0/16", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "10.0.0.0/16", "65001") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) } func TestValidate5(t *testing.T) { @@ -147,7 +147,7 @@ func TestValidate5(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.128.0").To4(), 17, 17, 65000, "")) r := validateOne(table, "10.0.0.0/16", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) } func TestValidate6(t *testing.T) { @@ -157,13 +157,13 @@ func TestValidate6(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 8, 32, 0, "")) r := validateOne(table, "10.0.0.0/7", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) r = validateOne(table, "10.0.0.0/8", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) r = validateOne(table, "10.0.0.0/24", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) } func TestValidate7(t *testing.T) { @@ -173,13 +173,13 @@ func TestValidate7(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, "")) r := validateOne(table, "10.0.0.0/24", "{65000}") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) r = validateOne(table, "10.0.0.0/24", "{65001}") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) r = validateOne(table, "10.0.0.0/24", "{65000,65001}") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND) } func TestValidate8(t *testing.T) { @@ -190,10 +190,10 @@ func TestValidate8(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, "")) r := validateOne(table, "10.0.0.0/24", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "10.0.0.0/24", "65001") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) } func TestValidate9(t *testing.T) { @@ -204,10 +204,10 @@ func TestValidate9(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65001, "")) r := validateOne(table, "10.0.0.0/24", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) r = validateOne(table, "10.0.0.0/24", "65001") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) } func TestValidate10(t *testing.T) { @@ -218,8 +218,8 @@ func TestValidate10(t *testing.T) { table.Add(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65001, "")) r := validateOne(table, "10.0.0.0/24", "65000") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_INVALID) r = validateOne(table, "10.0.0.0/24", "65001") - assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID) + assert.Equal(r, oc.RPKI_VALIDATION_RESULT_TYPE_VALID) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 454473401..1cc63faf5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -6,9 +6,9 @@ import ( apb "google.golang.org/protobuf/types/known/anypb" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" "github.com/osrg/gobgp/v3/pkg/apiutil" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/osrg/gobgp/v3/pkg/server" @@ -16,8 +16,8 @@ import ( // ReadConfigFile parses a config file into a BgpConfigSet which can be applied // using InitialConfig and UpdateConfig. -func ReadConfigFile(configFile, configType string) (*config.BgpConfigSet, error) { - return config.ReadConfigfile(configFile, configType) +func ReadConfigFile(configFile, configType string) (*oc.BgpConfigSet, error) { + return oc.ReadConfigfile(configFile, configType) } func marshalRouteTargets(l []string) ([]*apb.Any, error) { @@ -36,13 +36,13 @@ func marshalRouteTargets(l []string) ([]*apb.Any, error) { return rtList, nil } -func assignGlobalpolicy(ctx context.Context, bgpServer *server.BgpServer, a *config.ApplyPolicyConfig) { - toDefaultTable := func(r config.DefaultPolicyType) table.RouteType { +func assignGlobalpolicy(ctx context.Context, bgpServer *server.BgpServer, a *oc.ApplyPolicyConfig) { + toDefaultTable := func(r oc.DefaultPolicyType) table.RouteType { var def table.RouteType switch r { - case config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE: + case oc.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE: def = table.ROUTE_TYPE_ACCEPT - case config.DEFAULT_POLICY_TYPE_REJECT_ROUTE: + case oc.DEFAULT_POLICY_TYPE_REJECT_ROUTE: def = table.ROUTE_TYPE_REJECT } return def @@ -81,7 +81,7 @@ func assignGlobalpolicy(ctx context.Context, bgpServer *server.BgpServer, a *con } -func addPeerGroups(ctx context.Context, bgpServer *server.BgpServer, addedPg []config.PeerGroup) { +func addPeerGroups(ctx context.Context, bgpServer *server.BgpServer, addedPg []oc.PeerGroup) { for _, pg := range addedPg { bgpServer.Log().Info("Add PeerGroup", log.Fields{ @@ -90,7 +90,7 @@ func addPeerGroups(ctx context.Context, bgpServer *server.BgpServer, addedPg []c }) if err := bgpServer.AddPeerGroup(ctx, &api.AddPeerGroupRequest{ - PeerGroup: config.NewPeerGroupFromConfigStruct(&pg), + PeerGroup: oc.NewPeerGroupFromConfigStruct(&pg), }); err != nil { bgpServer.Log().Warn("Failed to add PeerGroup", log.Fields{ @@ -101,7 +101,7 @@ func addPeerGroups(ctx context.Context, bgpServer *server.BgpServer, addedPg []c } } -func deletePeerGroups(ctx context.Context, bgpServer *server.BgpServer, deletedPg []config.PeerGroup) { +func deletePeerGroups(ctx context.Context, bgpServer *server.BgpServer, deletedPg []oc.PeerGroup) { for _, pg := range deletedPg { bgpServer.Log().Info("delete PeerGroup", log.Fields{ @@ -119,14 +119,14 @@ func deletePeerGroups(ctx context.Context, bgpServer *server.BgpServer, deletedP } } -func updatePeerGroups(ctx context.Context, bgpServer *server.BgpServer, updatedPg []config.PeerGroup) bool { +func updatePeerGroups(ctx context.Context, bgpServer *server.BgpServer, updatedPg []oc.PeerGroup) bool { for _, pg := range updatedPg { bgpServer.Log().Info("update PeerGroup", log.Fields{ "Topic": "config", "Key": pg.Config.PeerGroupName}) if u, err := bgpServer.UpdatePeerGroup(ctx, &api.UpdatePeerGroupRequest{ - PeerGroup: config.NewPeerGroupFromConfigStruct(&pg), + PeerGroup: oc.NewPeerGroupFromConfigStruct(&pg), }); err != nil { bgpServer.Log().Warn("Failed to update PeerGroup", log.Fields{ @@ -140,7 +140,7 @@ func updatePeerGroups(ctx context.Context, bgpServer *server.BgpServer, updatedP return false } -func addDynamicNeighbors(ctx context.Context, bgpServer *server.BgpServer, dynamicNeighbors []config.DynamicNeighbor) { +func addDynamicNeighbors(ctx context.Context, bgpServer *server.BgpServer, dynamicNeighbors []oc.DynamicNeighbor) { for _, dn := range dynamicNeighbors { bgpServer.Log().Info("Add Dynamic Neighbor to PeerGroup", log.Fields{ @@ -163,14 +163,14 @@ func addDynamicNeighbors(ctx context.Context, bgpServer *server.BgpServer, dynam } } -func addNeighbors(ctx context.Context, bgpServer *server.BgpServer, added []config.Neighbor) { +func addNeighbors(ctx context.Context, bgpServer *server.BgpServer, added []oc.Neighbor) { for _, p := range added { bgpServer.Log().Info("Add Peer", log.Fields{ "Topic": "config", "Key": p.State.NeighborAddress}) if err := bgpServer.AddPeer(ctx, &api.AddPeerRequest{ - Peer: config.NewPeerFromConfigStruct(&p), + Peer: oc.NewPeerFromConfigStruct(&p), }); err != nil { bgpServer.Log().Warn("Failed to add Peer", log.Fields{ @@ -181,7 +181,7 @@ func addNeighbors(ctx context.Context, bgpServer *server.BgpServer, added []conf } } -func deleteNeighbors(ctx context.Context, bgpServer *server.BgpServer, deleted []config.Neighbor) { +func deleteNeighbors(ctx context.Context, bgpServer *server.BgpServer, deleted []oc.Neighbor) { for _, p := range deleted { bgpServer.Log().Info("Delete Peer", log.Fields{ @@ -199,14 +199,14 @@ func deleteNeighbors(ctx context.Context, bgpServer *server.BgpServer, deleted [ } } -func updateNeighbors(ctx context.Context, bgpServer *server.BgpServer, updated []config.Neighbor) bool { +func updateNeighbors(ctx context.Context, bgpServer *server.BgpServer, updated []oc.Neighbor) bool { for _, p := range updated { bgpServer.Log().Info("Update Peer", log.Fields{ "Topic": "config", "Key": p.State.NeighborAddress}) if u, err := bgpServer.UpdatePeer(ctx, &api.UpdatePeerRequest{ - Peer: config.NewPeerFromConfigStruct(&p), + Peer: oc.NewPeerFromConfigStruct(&p), }); err != nil { bgpServer.Log().Warn("Failed to update Peer", log.Fields{ @@ -225,9 +225,9 @@ func updateNeighbors(ctx context.Context, bgpServer *server.BgpServer, updated [ // configuration can be applied using UpdateConfig. The BgpConfigSet can be // obtained by calling ReadConfigFile. If graceful restart behavior is desired, // pass true for isGracefulRestart. Otherwise, pass false. -func InitialConfig(ctx context.Context, bgpServer *server.BgpServer, newConfig *config.BgpConfigSet, isGracefulRestart bool) (*config.BgpConfigSet, error) { +func InitialConfig(ctx context.Context, bgpServer *server.BgpServer, newConfig *oc.BgpConfigSet, isGracefulRestart bool) (*oc.BgpConfigSet, error) { if err := bgpServer.StartBgp(ctx, &api.StartBgpRequest{ - Global: config.NewGlobalFromConfigStruct(&newConfig.Global), + Global: oc.NewGlobalFromConfigStruct(&newConfig.Global), }); err != nil { bgpServer.Log().Fatal("failed to set global config", log.Fields{"Topic": "config", "Error": err}) @@ -329,7 +329,7 @@ func InitialConfig(ctx context.Context, bgpServer *server.BgpServer, newConfig * log.Fields{"Topic": "config", "Error": err}) } } - p := config.ConfigSetToRoutingPolicy(newConfig) + p := oc.ConfigSetToRoutingPolicy(newConfig) rp, err := table.NewAPIRoutingPolicyFromConfigStruct(p) if err != nil { bgpServer.Log().Fatal("failed to update policy config", @@ -365,14 +365,14 @@ func InitialConfig(ctx context.Context, bgpServer *server.BgpServer, newConfig * // hangle graceful restart and 2) requires a BgpConfigSet for the previous // configuration so that it can compute the delta between it and the new // config. The new BgpConfigSet can be obtained using ReadConfigFile. -func UpdateConfig(ctx context.Context, bgpServer *server.BgpServer, c, newConfig *config.BgpConfigSet) (*config.BgpConfigSet, error) { - addedPg, deletedPg, updatedPg := config.UpdatePeerGroupConfig(bgpServer.Log(), c, newConfig) - added, deleted, updated := config.UpdateNeighborConfig(bgpServer.Log(), c, newConfig) - updatePolicy := config.CheckPolicyDifference(bgpServer.Log(), config.ConfigSetToRoutingPolicy(c), config.ConfigSetToRoutingPolicy(newConfig)) +func UpdateConfig(ctx context.Context, bgpServer *server.BgpServer, c, newConfig *oc.BgpConfigSet) (*oc.BgpConfigSet, error) { + addedPg, deletedPg, updatedPg := oc.UpdatePeerGroupConfig(bgpServer.Log(), c, newConfig) + added, deleted, updated := oc.UpdateNeighborConfig(bgpServer.Log(), c, newConfig) + updatePolicy := oc.CheckPolicyDifference(bgpServer.Log(), oc.ConfigSetToRoutingPolicy(c), oc.ConfigSetToRoutingPolicy(newConfig)) if updatePolicy { bgpServer.Log().Info("policy config is update", log.Fields{"Topic": "config"}) - p := config.ConfigSetToRoutingPolicy(newConfig) + p := oc.ConfigSetToRoutingPolicy(newConfig) rp, err := table.NewAPIRoutingPolicyFromConfigStruct(p) if err != nil { bgpServer.Log().Warn("failed to update policy config", diff --git a/internal/pkg/config/bgp_configs.go b/pkg/config/oc/bgp_configs.go similarity index 99% rename from internal/pkg/config/bgp_configs.go rename to pkg/config/oc/bgp_configs.go index 22920af49..ff917d786 100644 --- a/internal/pkg/config/bgp_configs.go +++ b/pkg/config/oc/bgp_configs.go @@ -18,7 +18,7 @@ // Code generated by pyang. DO NOT EDIT. -package config +package oc import ( "fmt" diff --git a/internal/pkg/config/bgp_configs_test.go b/pkg/config/oc/bgp_configs_test.go similarity index 99% rename from internal/pkg/config/bgp_configs_test.go rename to pkg/config/oc/bgp_configs_test.go index 6d6853a74..ed676c469 100644 --- a/internal/pkg/config/bgp_configs_test.go +++ b/pkg/config/oc/bgp_configs_test.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config +package oc import ( "bufio" diff --git a/internal/pkg/config/default.go b/pkg/config/oc/default.go similarity index 99% rename from internal/pkg/config/default.go rename to pkg/config/oc/default.go index eb47b6111..a61d312c4 100644 --- a/internal/pkg/config/default.go +++ b/pkg/config/oc/default.go @@ -1,4 +1,4 @@ -package config +package oc import ( "encoding/binary" diff --git a/internal/pkg/config/default_linux.go b/pkg/config/oc/default_linux.go similarity index 99% rename from internal/pkg/config/default_linux.go rename to pkg/config/oc/default_linux.go index 878988022..f5aaf5cdc 100644 --- a/internal/pkg/config/default_linux.go +++ b/pkg/config/oc/default_linux.go @@ -15,7 +15,7 @@ //go:build linux // +build linux -package config +package oc import ( "fmt" diff --git a/internal/pkg/config/default_nonlinux.go b/pkg/config/oc/default_nonlinux.go similarity index 98% rename from internal/pkg/config/default_nonlinux.go rename to pkg/config/oc/default_nonlinux.go index e9ad86dc4..60915466a 100644 --- a/internal/pkg/config/default_nonlinux.go +++ b/pkg/config/oc/default_nonlinux.go @@ -15,7 +15,7 @@ //go:build !linux // +build !linux -package config +package oc import ( "fmt" diff --git a/internal/pkg/config/serve.go b/pkg/config/oc/serve.go similarity index 99% rename from internal/pkg/config/serve.go rename to pkg/config/oc/serve.go index 84db10221..79996d020 100644 --- a/internal/pkg/config/serve.go +++ b/pkg/config/oc/serve.go @@ -1,4 +1,4 @@ -package config +package oc import ( "github.com/spf13/viper" diff --git a/internal/pkg/config/util.go b/pkg/config/oc/util.go similarity index 99% rename from internal/pkg/config/util.go rename to pkg/config/oc/util.go index 5736a4c1c..6b4f98e22 100644 --- a/internal/pkg/config/util.go +++ b/pkg/config/oc/util.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config +package oc import ( "fmt" diff --git a/internal/pkg/config/util_test.go b/pkg/config/oc/util_test.go similarity index 99% rename from internal/pkg/config/util_test.go rename to pkg/config/oc/util_test.go index 62fe1c1c8..6da07ba08 100644 --- a/internal/pkg/config/util_test.go +++ b/pkg/config/oc/util_test.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config +package oc import ( "testing" diff --git a/pkg/server/bmp.go b/pkg/server/bmp.go index d7ba67534..950b7e5ab 100644 --- a/pkg/server/bmp.go +++ b/pkg/server/bmp.go @@ -24,8 +24,8 @@ import ( "time" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/osrg/gobgp/v3/pkg/packet/bmp" @@ -127,16 +127,16 @@ func (b *bmpClient) loop() { atomic.StoreInt64(&b.downtime, time.Now().Unix()) }() ops := []watchOption{watchPeer()} - if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_BOTH { + if b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_BOTH { b.s.logger.Warn("both option for route-monitoring-policy is obsoleted", log.Fields{"Topic": "bmp"}) } - if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY || b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL { + if b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY || b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL { ops = append(ops, watchUpdate(true, "", "")) } - if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY || b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL { + if b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY || b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL { ops = append(ops, watchPostUpdate(true, "", "")) } - if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_LOCAL_RIB || b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL { + if b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_LOCAL_RIB || b.c.RouteMonitoringPolicy == oc.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL { ops = append(ops, watchBestPath(true)) } if b.c.RouteMirroringEnabled { @@ -275,7 +275,7 @@ type bmpClient struct { s *BgpServer dead chan struct{} host string - c *config.BmpServerConfig + c *oc.BmpServerConfig ribout ribout uptime int64 downtime int64 @@ -360,7 +360,7 @@ func bmpPeerRouteMirroring(peerType uint8, peerDist uint64, peerInfo *table.Peer ) } -func (b *bmpClientManager) addServer(c *config.BmpServerConfig) error { +func (b *bmpClientManager) addServer(c *oc.BmpServerConfig) error { host := net.JoinHostPort(c.Address, strconv.Itoa(int(c.Port))) if _, y := b.clientMap[host]; y { return fmt.Errorf("bmp client %s is already configured", host) @@ -376,7 +376,7 @@ func (b *bmpClientManager) addServer(c *config.BmpServerConfig) error { return nil } -func (b *bmpClientManager) deleteServer(c *config.BmpServerConfig) error { +func (b *bmpClientManager) deleteServer(c *oc.BmpServerConfig) error { host := net.JoinHostPort(c.Address, strconv.Itoa(int(c.Port))) if c, y := b.clientMap[host]; !y { return fmt.Errorf("bmp client %s isn't found", host) diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go index ed64d26d5..07d03bc17 100644 --- a/pkg/server/fsm.go +++ b/pkg/server/fsm.go @@ -28,9 +28,9 @@ import ( "time" "github.com/eapache/channels" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" "github.com/osrg/gobgp/v3/internal/pkg/version" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/osrg/gobgp/v3/pkg/packet/bmp" @@ -172,8 +172,8 @@ type adminStateOperation struct { } type fsm struct { - gConf *config.Global - pConf *config.Neighbor + gConf *oc.Global + pConf *oc.Neighbor lock sync.RWMutex state bgp.FSMState outgoingCh *channels.InfiniteChannel @@ -262,12 +262,12 @@ func (fsm *fsm) bmpStatsUpdate(statType uint16, increment int) { } } -func newFSM(gConf *config.Global, pConf *config.Neighbor, logger log.Logger) *fsm { +func newFSM(gConf *oc.Global, pConf *oc.Neighbor, logger log.Logger) *fsm { adminState := adminStateUp if pConf.Config.AdminDown { adminState = adminStateDown } - pConf.State.SessionState = config.IntToSessionStateMap[int(bgp.BGP_FSM_IDLE)] + pConf.State.SessionState = oc.IntToSessionStateMap[int(bgp.BGP_FSM_IDLE)] pConf.Timers.State.Downtime = time.Now().Unix() fsm := &fsm{ gConf: gConf, @@ -515,7 +515,7 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) { if fsm.pConf.TtlSecurity.Config.Enabled { ttl = 255 ttlMin = fsm.pConf.TtlSecurity.Config.TtlMin - } else if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL { + } else if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == oc.PEER_TYPE_EXTERNAL { ttl = 1 if fsm.pConf.EbgpMultihop.Config.Enabled { ttl = fsm.pConf.EbgpMultihop.Config.MultihopTtl @@ -688,7 +688,7 @@ func setPeerConnTTL(fsm *fsm) error { if fsm.pConf.TtlSecurity.Config.Enabled { ttl = 255 ttlMin = int(fsm.pConf.TtlSecurity.Config.TtlMin) - } else if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL { + } else if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == oc.PEER_TYPE_EXTERNAL { if fsm.pConf.EbgpMultihop.Config.Enabled { ttl = int(fsm.pConf.EbgpMultihop.Config.MultihopTtl) } else if fsm.pConf.Transport.Config.Ttl != 0 { @@ -724,7 +724,7 @@ func setPeerConnMSS(fsm *fsm) error { return nil } -func capAddPathFromConfig(pConf *config.Neighbor) bgp.ParameterCapabilityInterface { +func capAddPathFromConfig(pConf *oc.Neighbor) bgp.ParameterCapabilityInterface { tuples := make([]*bgp.CapAddPathTuple, 0, len(pConf.AfiSafis)) for _, af := range pConf.AfiSafis { var mode bgp.BGPAddPathMode @@ -744,13 +744,13 @@ func capAddPathFromConfig(pConf *config.Neighbor) bgp.ParameterCapabilityInterfa return bgp.NewCapAddPath(tuples) } -func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInterface { +func capabilitiesFromConfig(pConf *oc.Neighbor) []bgp.ParameterCapabilityInterface { fqdn, _ := os.Hostname() caps := make([]bgp.ParameterCapabilityInterface, 0, 4) caps = append(caps, bgp.NewCapRouteRefresh()) caps = append(caps, bgp.NewCapFQDN(fqdn, "")) - if pConf.Config.SendSoftwareVersion || pConf.Config.PeerType == config.PEER_TYPE_INTERNAL { + if pConf.Config.SendSoftwareVersion || pConf.Config.PeerType == oc.PEER_TYPE_INTERNAL { softwareVersion := fmt.Sprintf("GoBGP/%s", version.Version()) caps = append(caps, bgp.NewCapSoftwareVersion(softwareVersion)) } @@ -798,7 +798,7 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt // Extended Nexthop Capability (Code 5) tuples := []*bgp.CapExtendedNexthopTuple{} - families, _ := config.AfiSafis(pConf.AfiSafis).ToRfList() + families, _ := oc.AfiSafis(pConf.AfiSafis).ToRfList() for _, family := range families { if family == bgp.RF_IPv6_UC { continue @@ -818,7 +818,7 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt return caps } -func buildopen(gConf *config.Global, pConf *config.Neighbor) *bgp.BGPMessage { +func buildopen(gConf *oc.Global, pConf *oc.Neighbor) *bgp.BGPMessage { caps := capabilitiesFromConfig(pConf) opt := bgp.NewOptionParameterCapability(caps) holdTime := uint16(pConf.Timers.Config.HoldTime) @@ -1182,7 +1182,7 @@ func (h *fsmHandler) recvMessage(ctx context.Context, wg *sync.WaitGroup) error return nil } -func open2Cap(open *bgp.BGPOpen, n *config.Neighbor) (map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface, map[bgp.RouteFamily]bgp.BGPAddPathMode) { +func open2Cap(open *bgp.BGPOpen, n *oc.Neighbor) (map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface, map[bgp.RouteFamily]bgp.BGPAddPathMode) { capMap := make(map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface) for _, p := range open.OptParams { if paramCap, y := p.(*bgp.OptionParameterCapability); y { @@ -1330,9 +1330,9 @@ func (h *fsmHandler) opensent(ctx context.Context) (bgp.FSMState, *fsmStateReaso fsm.lock.RUnlock() if asnNegotiationSkipped { fsm.lock.Lock() - typ := config.PEER_TYPE_EXTERNAL + typ := oc.PEER_TYPE_EXTERNAL if fsm.peerInfo.LocalAS == peerAs { - typ = config.PEER_TYPE_INTERNAL + typ = oc.PEER_TYPE_INTERNAL } fsm.pConf.State.PeerType = typ fsm.logger.Info("skipped asn negotiation", diff --git a/pkg/server/fsm_test.go b/pkg/server/fsm_test.go index fe9944a12..1920935d7 100644 --- a/pkg/server/fsm_test.go +++ b/pkg/server/fsm_test.go @@ -25,7 +25,7 @@ import ( "time" "github.com/eapache/channels" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" @@ -370,7 +370,7 @@ func TestBadBGPIdentifier(t *testing.T) { func makePeerAndHandler() (*peer, *fsmHandler) { p := &peer{ - fsm: newFSM(&config.Global{}, &config.Neighbor{}, log.NewDefaultLogger()), + fsm: newFSM(&oc.Global{}, &oc.Neighbor{}, log.NewDefaultLogger()), } h := &fsmHandler{ diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index ad05d8fe4..7a0120a71 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -35,9 +35,9 @@ import ( tspb "google.golang.org/protobuf/types/known/timestamppb" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" "github.com/osrg/gobgp/v3/pkg/apiutil" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -272,8 +272,8 @@ func (s *server) SetPolicies(ctx context.Context, r *api.SetPoliciesRequest) (*e return &emptypb.Empty{}, s.bgpServer.SetPolicies(ctx, r) } -func newRoutingPolicyFromApiStruct(arg *api.SetPoliciesRequest) (*config.RoutingPolicy, error) { - policyDefinitions := make([]config.PolicyDefinition, 0, len(arg.Policies)) +func newRoutingPolicyFromApiStruct(arg *api.SetPoliciesRequest) (*oc.RoutingPolicy, error) { + policyDefinitions := make([]oc.PolicyDefinition, 0, len(arg.Policies)) for _, p := range arg.Policies { pd, err := newConfigPolicyFromApiStruct(p) if err != nil { @@ -287,7 +287,7 @@ func newRoutingPolicyFromApiStruct(arg *api.SetPoliciesRequest) (*config.Routing return nil, err } - return &config.RoutingPolicy{ + return &oc.RoutingPolicy{ DefinedSets: *definedSets, PolicyDefinitions: policyDefinitions, }, nil @@ -501,7 +501,7 @@ func (s *server) DeleteVrf(ctx context.Context, r *api.DeleteVrfRequest) (*empty return &emptypb.Empty{}, s.bgpServer.DeleteVrf(ctx, r) } -func readMpGracefulRestartFromAPIStruct(c *config.MpGracefulRestart, a *api.MpGracefulRestart) { +func readMpGracefulRestartFromAPIStruct(c *oc.MpGracefulRestart, a *api.MpGracefulRestart) { if c == nil || a == nil { return } @@ -510,16 +510,16 @@ func readMpGracefulRestartFromAPIStruct(c *config.MpGracefulRestart, a *api.MpGr } } -func readAfiSafiConfigFromAPIStruct(c *config.AfiSafiConfig, a *api.AfiSafiConfig) { +func readAfiSafiConfigFromAPIStruct(c *oc.AfiSafiConfig, a *api.AfiSafiConfig) { if c == nil || a == nil { return } rf := bgp.AfiSafiToRouteFamily(uint16(a.Family.Afi), uint8(a.Family.Safi)) - c.AfiSafiName = config.AfiSafiType(rf.String()) + c.AfiSafiName = oc.AfiSafiType(rf.String()) c.Enabled = a.Enabled } -func readAfiSafiStateFromAPIStruct(s *config.AfiSafiState, a *api.AfiSafiConfig) { +func readAfiSafiStateFromAPIStruct(s *oc.AfiSafiState, a *api.AfiSafiConfig) { if s == nil || a == nil { return } @@ -527,23 +527,23 @@ func readAfiSafiStateFromAPIStruct(s *config.AfiSafiState, a *api.AfiSafiConfig) s.Family = bgp.AfiSafiToRouteFamily(uint16(a.Family.Afi), uint8(a.Family.Safi)) } -func readPrefixLimitFromAPIStruct(c *config.PrefixLimit, a *api.PrefixLimit) { +func readPrefixLimitFromAPIStruct(c *oc.PrefixLimit, a *api.PrefixLimit) { if c == nil || a == nil { return } c.Config.MaxPrefixes = a.MaxPrefixes - c.Config.ShutdownThresholdPct = config.Percentage(a.ShutdownThresholdPct) + c.Config.ShutdownThresholdPct = oc.Percentage(a.ShutdownThresholdPct) } -func readApplyPolicyFromAPIStruct(c *config.ApplyPolicy, a *api.ApplyPolicy) { +func readApplyPolicyFromAPIStruct(c *oc.ApplyPolicy, a *api.ApplyPolicy) { if c == nil || a == nil { return } - f := func(a api.RouteAction) config.DefaultPolicyType { + f := func(a api.RouteAction) oc.DefaultPolicyType { if a == api.RouteAction_ACCEPT { - return config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE + return oc.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE } else if a == api.RouteAction_REJECT { - return config.DEFAULT_POLICY_TYPE_REJECT_ROUTE + return oc.DEFAULT_POLICY_TYPE_REJECT_ROUTE } return "" } @@ -568,7 +568,7 @@ func readApplyPolicyFromAPIStruct(c *config.ApplyPolicy, a *api.ApplyPolicy) { } } -func readRouteSelectionOptionsFromAPIStruct(c *config.RouteSelectionOptions, a *api.RouteSelectionOptions) { +func readRouteSelectionOptionsFromAPIStruct(c *oc.RouteSelectionOptions, a *api.RouteSelectionOptions) { if c == nil || a == nil { return } @@ -582,7 +582,7 @@ func readRouteSelectionOptionsFromAPIStruct(c *config.RouteSelectionOptions, a * } } -func readUseMultiplePathsFromAPIStruct(c *config.UseMultiplePaths, a *api.UseMultiplePaths) { +func readUseMultiplePathsFromAPIStruct(c *oc.UseMultiplePaths, a *api.UseMultiplePaths) { if c == nil || a == nil { return } @@ -590,23 +590,23 @@ func readUseMultiplePathsFromAPIStruct(c *config.UseMultiplePaths, a *api.UseMul c.Config.Enabled = a.Config.Enabled } if a.Ebgp != nil && a.Ebgp.Config != nil { - c.Ebgp = config.Ebgp{ - Config: config.EbgpConfig{ + c.Ebgp = oc.Ebgp{ + Config: oc.EbgpConfig{ AllowMultipleAs: a.Ebgp.Config.AllowMultipleAsn, MaximumPaths: a.Ebgp.Config.MaximumPaths, }, } } if a.Ibgp != nil && a.Ibgp.Config != nil { - c.Ibgp = config.Ibgp{ - Config: config.IbgpConfig{ + c.Ibgp = oc.Ibgp{ + Config: oc.IbgpConfig{ MaximumPaths: a.Ibgp.Config.MaximumPaths, }, } } } -func readRouteTargetMembershipFromAPIStruct(c *config.RouteTargetMembership, a *api.RouteTargetMembership) { +func readRouteTargetMembershipFromAPIStruct(c *oc.RouteTargetMembership, a *api.RouteTargetMembership) { if c == nil || a == nil { return } @@ -615,7 +615,7 @@ func readRouteTargetMembershipFromAPIStruct(c *config.RouteTargetMembership, a * } } -func readLongLivedGracefulRestartFromAPIStruct(c *config.LongLivedGracefulRestart, a *api.LongLivedGracefulRestart) { +func readLongLivedGracefulRestartFromAPIStruct(c *oc.LongLivedGracefulRestart, a *api.LongLivedGracefulRestart) { if c == nil || a == nil { return } @@ -625,7 +625,7 @@ func readLongLivedGracefulRestartFromAPIStruct(c *config.LongLivedGracefulRestar } } -func readAddPathsFromAPIStruct(c *config.AddPaths, a *api.AddPaths) { +func readAddPathsFromAPIStruct(c *oc.AddPaths, a *api.AddPaths) { if c == nil || a == nil { return } @@ -635,8 +635,8 @@ func readAddPathsFromAPIStruct(c *config.AddPaths, a *api.AddPaths) { } } -func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { - pconf := &config.Neighbor{} +func newNeighborFromAPIStruct(a *api.Peer) (*oc.Neighbor, error) { + pconf := &oc.Neighbor{} if a.Conf != nil { pconf.Config.PeerAs = a.Conf.PeerAsn pconf.Config.LocalAs = a.Conf.LocalAsn @@ -644,7 +644,7 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { pconf.Config.RouteFlapDamping = a.Conf.RouteFlapDamping pconf.Config.Description = a.Conf.Description pconf.Config.PeerGroup = a.Conf.PeerGroup - pconf.Config.PeerType = config.IntToPeerTypeMap[int(a.Conf.Type)] + pconf.Config.PeerType = oc.IntToPeerTypeMap[int(a.Conf.Type)] pconf.Config.NeighborAddress = a.Conf.NeighborAddress pconf.Config.AdminDown = a.Conf.AdminDown pconf.Config.NeighborInterface = a.Conf.NeighborInterface @@ -655,9 +655,9 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { switch a.Conf.RemovePrivate { case api.RemovePrivate_REMOVE_ALL: - pconf.Config.RemovePrivateAs = config.REMOVE_PRIVATE_AS_OPTION_ALL + pconf.Config.RemovePrivateAs = oc.REMOVE_PRIVATE_AS_OPTION_ALL case api.RemovePrivate_REPLACE: - pconf.Config.RemovePrivateAs = config.REMOVE_PRIVATE_AS_OPTION_REPLACE + pconf.Config.RemovePrivateAs = oc.REMOVE_PRIVATE_AS_OPTION_REPLACE } if a.State != nil { @@ -676,7 +676,7 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { } for _, af := range a.AfiSafis { - afiSafi := config.AfiSafi{} + afiSafi := oc.AfiSafi{} readMpGracefulRestartFromAPIStruct(&afiSafi.MpGracefulRestart, af.MpGracefulRestart) readAfiSafiConfigFromAPIStruct(&afiSafi.Config, af.Config) readAfiSafiStateFromAPIStruct(&afiSafi.State, af.Config) @@ -705,7 +705,7 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { } } if a.RouteReflector != nil { - pconf.RouteReflector.Config.RouteReflectorClusterId = config.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) + pconf.RouteReflector.Config.RouteReflectorClusterId = oc.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) pconf.RouteReflector.Config.RouteReflectorClient = a.RouteReflector.RouteReflectorClient } if a.RouteServer != nil { @@ -739,11 +739,11 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { pconf.TtlSecurity.Config.TtlMin = uint8(a.TtlSecurity.TtlMin) } if a.State != nil { - pconf.State.SessionState = config.SessionState(strings.ToUpper(string(a.State.SessionState))) - pconf.State.AdminState = config.IntToAdminStateMap[int(a.State.AdminState)] + pconf.State.SessionState = oc.SessionState(strings.ToUpper(string(a.State.SessionState))) + pconf.State.AdminState = oc.IntToAdminStateMap[int(a.State.AdminState)] pconf.State.PeerAs = a.State.PeerAsn - pconf.State.PeerType = config.IntToPeerTypeMap[int(a.State.Type)] + pconf.State.PeerType = oc.IntToPeerTypeMap[int(a.State.Type)] pconf.State.NeighborAddress = a.State.NeighborAddress if a.State.Messages != nil { @@ -769,8 +769,8 @@ func newNeighborFromAPIStruct(a *api.Peer) (*config.Neighbor, error) { return pconf, nil } -func newPeerGroupFromAPIStruct(a *api.PeerGroup) (*config.PeerGroup, error) { - pconf := &config.PeerGroup{} +func newPeerGroupFromAPIStruct(a *api.PeerGroup) (*oc.PeerGroup, error) { + pconf := &oc.PeerGroup{} if a.Conf != nil { pconf.Config.PeerAs = a.Conf.PeerAsn pconf.Config.LocalAs = a.Conf.LocalAsn @@ -781,13 +781,13 @@ func newPeerGroupFromAPIStruct(a *api.PeerGroup) (*config.PeerGroup, error) { switch a.Conf.RemovePrivate { case api.RemovePrivate_REMOVE_ALL: - pconf.Config.RemovePrivateAs = config.REMOVE_PRIVATE_AS_OPTION_ALL + pconf.Config.RemovePrivateAs = oc.REMOVE_PRIVATE_AS_OPTION_ALL case api.RemovePrivate_REPLACE: - pconf.Config.RemovePrivateAs = config.REMOVE_PRIVATE_AS_OPTION_REPLACE + pconf.Config.RemovePrivateAs = oc.REMOVE_PRIVATE_AS_OPTION_REPLACE } for _, af := range a.AfiSafis { - afiSafi := config.AfiSafi{} + afiSafi := oc.AfiSafi{} readMpGracefulRestartFromAPIStruct(&afiSafi.MpGracefulRestart, af.MpGracefulRestart) readAfiSafiConfigFromAPIStruct(&afiSafi.Config, af.Config) readAfiSafiStateFromAPIStruct(&afiSafi.State, af.Config) @@ -816,7 +816,7 @@ func newPeerGroupFromAPIStruct(a *api.PeerGroup) (*config.PeerGroup, error) { } } if a.RouteReflector != nil { - pconf.RouteReflector.Config.RouteReflectorClusterId = config.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) + pconf.RouteReflector.Config.RouteReflectorClusterId = oc.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) pconf.RouteReflector.Config.RouteReflectorClient = a.RouteReflector.RouteReflectorClient } if a.RouteServer != nil { @@ -851,7 +851,7 @@ func newPeerGroupFromAPIStruct(a *api.PeerGroup) (*config.PeerGroup, error) { pconf.State.TotalPaths = a.Info.TotalPaths pconf.State.TotalPrefixes = a.Info.TotalPrefixes pconf.State.PeerAs = a.Info.PeerAsn - pconf.State.PeerType = config.IntToPeerTypeMap[int(a.Info.Type)] + pconf.State.PeerType = oc.IntToPeerTypeMap[int(a.Info.Type)] } return pconf, nil } @@ -905,24 +905,24 @@ func newPrefixFromApiStruct(a *api.Prefix) (*table.Prefix, error) { }, nil } -func newConfigPrefixFromAPIStruct(a *api.Prefix) (*config.Prefix, error) { +func newConfigPrefixFromAPIStruct(a *api.Prefix) (*oc.Prefix, error) { _, prefix, err := net.ParseCIDR(a.IpPrefix) if err != nil { return nil, err } - return &config.Prefix{ + return &oc.Prefix{ IpPrefix: prefix.String(), MasklengthRange: fmt.Sprintf("%d..%d", a.MaskLengthMin, a.MaskLengthMax), }, nil } -func newConfigDefinedSetsFromApiStruct(a []*api.DefinedSet) (*config.DefinedSets, error) { - ps := make([]config.PrefixSet, 0) - ns := make([]config.NeighborSet, 0) - as := make([]config.AsPathSet, 0) - cs := make([]config.CommunitySet, 0) - es := make([]config.ExtCommunitySet, 0) - ls := make([]config.LargeCommunitySet, 0) +func newConfigDefinedSetsFromApiStruct(a []*api.DefinedSet) (*oc.DefinedSets, error) { + ps := make([]oc.PrefixSet, 0) + ns := make([]oc.NeighborSet, 0) + as := make([]oc.AsPathSet, 0) + cs := make([]oc.CommunitySet, 0) + es := make([]oc.ExtCommunitySet, 0) + ls := make([]oc.LargeCommunitySet, 0) for _, ds := range a { if ds.Name == "" { @@ -930,7 +930,7 @@ func newConfigDefinedSetsFromApiStruct(a []*api.DefinedSet) (*config.DefinedSets } switch table.DefinedType(ds.DefinedType) { case table.DEFINED_TYPE_PREFIX: - prefixes := make([]config.Prefix, 0, len(ds.Prefixes)) + prefixes := make([]oc.Prefix, 0, len(ds.Prefixes)) for _, p := range ds.Prefixes { prefix, err := newConfigPrefixFromAPIStruct(p) if err != nil { @@ -938,32 +938,32 @@ func newConfigDefinedSetsFromApiStruct(a []*api.DefinedSet) (*config.DefinedSets } prefixes = append(prefixes, *prefix) } - ps = append(ps, config.PrefixSet{ + ps = append(ps, oc.PrefixSet{ PrefixSetName: ds.Name, PrefixList: prefixes, }) case table.DEFINED_TYPE_NEIGHBOR: - ns = append(ns, config.NeighborSet{ + ns = append(ns, oc.NeighborSet{ NeighborSetName: ds.Name, NeighborInfoList: ds.List, }) case table.DEFINED_TYPE_AS_PATH: - as = append(as, config.AsPathSet{ + as = append(as, oc.AsPathSet{ AsPathSetName: ds.Name, AsPathList: ds.List, }) case table.DEFINED_TYPE_COMMUNITY: - cs = append(cs, config.CommunitySet{ + cs = append(cs, oc.CommunitySet{ CommunitySetName: ds.Name, CommunityList: ds.List, }) case table.DEFINED_TYPE_EXT_COMMUNITY: - es = append(es, config.ExtCommunitySet{ + es = append(es, oc.ExtCommunitySet{ ExtCommunitySetName: ds.Name, ExtCommunityList: ds.List, }) case table.DEFINED_TYPE_LARGE_COMMUNITY: - ls = append(ls, config.LargeCommunitySet{ + ls = append(ls, oc.LargeCommunitySet{ LargeCommunitySetName: ds.Name, LargeCommunityList: ds.List, }) @@ -972,10 +972,10 @@ func newConfigDefinedSetsFromApiStruct(a []*api.DefinedSet) (*config.DefinedSets } } - return &config.DefinedSets{ + return &oc.DefinedSets{ PrefixSets: ps, NeighborSets: ns, - BgpDefinedSets: config.BgpDefinedSets{ + BgpDefinedSets: oc.BgpDefinedSets{ AsPathSets: as, CommunitySets: cs, ExtCommunitySets: es, @@ -1010,22 +1010,22 @@ func newDefinedSetFromApiStruct(a *api.DefinedSet) (table.DefinedSet, error) { } return table.NewNeighborSetFromApiStruct(a.Name, list) case table.DEFINED_TYPE_AS_PATH: - return table.NewAsPathSet(config.AsPathSet{ + return table.NewAsPathSet(oc.AsPathSet{ AsPathSetName: a.Name, AsPathList: a.List, }) case table.DEFINED_TYPE_COMMUNITY: - return table.NewCommunitySet(config.CommunitySet{ + return table.NewCommunitySet(oc.CommunitySet{ CommunitySetName: a.Name, CommunityList: a.List, }) case table.DEFINED_TYPE_EXT_COMMUNITY: - return table.NewExtCommunitySet(config.ExtCommunitySet{ + return table.NewExtCommunitySet(oc.ExtCommunitySet{ ExtCommunitySetName: a.Name, ExtCommunityList: a.List, }) case table.DEFINED_TYPE_LARGE_COMMUNITY: - return table.NewLargeCommunitySet(config.LargeCommunitySet{ + return table.NewLargeCommunitySet(oc.LargeCommunitySet{ LargeCommunitySetName: a.Name, LargeCommunityList: a.List, }) @@ -1057,18 +1057,18 @@ func (s *server) DeleteDefinedSet(ctx context.Context, r *api.DeleteDefinedSetRe var _regexpMedActionType = regexp.MustCompile(`([+-]?)(\d+)`) -func matchSetOptionsRestrictedTypeToAPI(t config.MatchSetOptionsRestrictedType) api.MatchSet_Type { +func matchSetOptionsRestrictedTypeToAPI(t oc.MatchSetOptionsRestrictedType) api.MatchSet_Type { t = t.DefaultAsNeeded() switch t { - case config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY: + case oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY: return api.MatchSet_ANY - case config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT: + case oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT: return api.MatchSet_INVERT } return api.MatchSet_ANY } -func toStatementApi(s *config.Statement) *api.Statement { +func toStatementApi(s *oc.Statement) *api.Statement { cs := &api.Conditions{} if s.Conditions.MatchPrefixSet.PrefixSet != "" { cs.PrefixSet = &api.MatchSet{ @@ -1132,9 +1132,9 @@ func toStatementApi(s *config.Statement) *api.Statement { as := &api.Actions{ RouteAction: func() api.RouteAction { switch s.Actions.RouteDisposition { - case config.ROUTE_DISPOSITION_ACCEPT_ROUTE: + case oc.ROUTE_DISPOSITION_ACCEPT_ROUTE: return api.RouteAction_ACCEPT - case config.ROUTE_DISPOSITION_REJECT_ROUTE: + case oc.ROUTE_DISPOSITION_REJECT_ROUTE: return api.RouteAction_REJECT } return api.RouteAction_NONE @@ -1144,7 +1144,7 @@ func toStatementApi(s *config.Statement) *api.Statement { return nil } return &api.CommunityAction{ - Type: api.CommunityAction_Type(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetCommunity.Options)]), + Type: api.CommunityAction_Type(oc.BgpSetCommunityOptionTypeToIntMap[oc.BgpSetCommunityOptionType(s.Actions.BgpActions.SetCommunity.Options)]), Communities: s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList} }(), Med: func() *api.MedAction { @@ -1192,7 +1192,7 @@ func toStatementApi(s *config.Statement) *api.Statement { return nil } return &api.CommunityAction{ - Type: api.CommunityAction_Type(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetExtCommunity.Options)]), + Type: api.CommunityAction_Type(oc.BgpSetCommunityOptionTypeToIntMap[oc.BgpSetCommunityOptionType(s.Actions.BgpActions.SetExtCommunity.Options)]), Communities: s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.CommunitiesList, } }(), @@ -1201,7 +1201,7 @@ func toStatementApi(s *config.Statement) *api.Statement { return nil } return &api.CommunityAction{ - Type: api.CommunityAction_Type(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetLargeCommunity.Options)]), + Type: api.CommunityAction_Type(oc.BgpSetCommunityOptionTypeToIntMap[oc.BgpSetCommunityOptionType(s.Actions.BgpActions.SetLargeCommunity.Options)]), Communities: s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList, } }(), @@ -1238,28 +1238,28 @@ func toStatementApi(s *config.Statement) *api.Statement { } } -func toConfigMatchSetOption(a api.MatchSet_Type) (config.MatchSetOptionsType, error) { - var typ config.MatchSetOptionsType +func toConfigMatchSetOption(a api.MatchSet_Type) (oc.MatchSetOptionsType, error) { + var typ oc.MatchSetOptionsType switch a { case api.MatchSet_ANY: - typ = config.MATCH_SET_OPTIONS_TYPE_ANY + typ = oc.MATCH_SET_OPTIONS_TYPE_ANY case api.MatchSet_ALL: - typ = config.MATCH_SET_OPTIONS_TYPE_ALL + typ = oc.MATCH_SET_OPTIONS_TYPE_ALL case api.MatchSet_INVERT: - typ = config.MATCH_SET_OPTIONS_TYPE_INVERT + typ = oc.MATCH_SET_OPTIONS_TYPE_INVERT default: return typ, fmt.Errorf("invalid match type") } return typ, nil } -func toConfigMatchSetOptionRestricted(a api.MatchSet_Type) (config.MatchSetOptionsRestrictedType, error) { - var typ config.MatchSetOptionsRestrictedType +func toConfigMatchSetOptionRestricted(a api.MatchSet_Type) (oc.MatchSetOptionsRestrictedType, error) { + var typ oc.MatchSetOptionsRestrictedType switch a { case api.MatchSet_ANY: - typ = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + typ = oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY case api.MatchSet_INVERT: - typ = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT + typ = oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT default: return typ, fmt.Errorf("invalid match type") } @@ -1274,7 +1274,7 @@ func newPrefixConditionFromApiStruct(a *api.MatchSet) (*table.PrefixCondition, e if err != nil { return nil, err } - c := config.MatchPrefixSet{ + c := oc.MatchPrefixSet{ PrefixSet: a.Name, MatchSetOptions: typ, } @@ -1289,7 +1289,7 @@ func newNeighborConditionFromApiStruct(a *api.MatchSet) (*table.NeighborConditio if err != nil { return nil, err } - c := config.MatchNeighborSet{ + c := oc.MatchNeighborSet{ NeighborSet: a.Name, MatchSetOptions: typ, } @@ -1300,8 +1300,8 @@ func newAsPathLengthConditionFromApiStruct(a *api.AsPathLength) (*table.AsPathLe if a == nil { return nil, nil } - return table.NewAsPathLengthCondition(config.AsPathLength{ - Operator: config.IntToAttributeComparisonMap[int(a.Type)], + return table.NewAsPathLengthCondition(oc.AsPathLength{ + Operator: oc.IntToAttributeComparisonMap[int(a.Type)], Value: a.Length, }) } @@ -1314,7 +1314,7 @@ func newAsPathConditionFromApiStruct(a *api.MatchSet) (*table.AsPathCondition, e if err != nil { return nil, err } - c := config.MatchAsPathSet{ + c := oc.MatchAsPathSet{ AsPathSet: a.Name, MatchSetOptions: typ, } @@ -1325,14 +1325,14 @@ func newRpkiValidationConditionFromApiStruct(a int32) (*table.RpkiValidationCond if a < 1 { return nil, nil } - return table.NewRpkiValidationCondition(config.IntToRpkiValidationResultTypeMap[int(a)]) + return table.NewRpkiValidationCondition(oc.IntToRpkiValidationResultTypeMap[int(a)]) } func newRouteTypeConditionFromApiStruct(a api.Conditions_RouteType) (*table.RouteTypeCondition, error) { if a == 0 { return nil, nil } - typ, ok := config.IntToRouteTypeMap[int(a)] + typ, ok := oc.IntToRouteTypeMap[int(a)] if !ok { return nil, fmt.Errorf("invalid route type: %d", a) } @@ -1347,7 +1347,7 @@ func newCommunityConditionFromApiStruct(a *api.MatchSet) (*table.CommunityCondit if err != nil { return nil, err } - c := config.MatchCommunitySet{ + c := oc.MatchCommunitySet{ CommunitySet: a.Name, MatchSetOptions: typ, } @@ -1362,7 +1362,7 @@ func newExtCommunityConditionFromApiStruct(a *api.MatchSet) (*table.ExtCommunity if err != nil { return nil, err } - c := config.MatchExtCommunitySet{ + c := oc.MatchExtCommunitySet{ ExtCommunitySet: a.Name, MatchSetOptions: typ, } @@ -1377,7 +1377,7 @@ func newLargeCommunityConditionFromApiStruct(a *api.MatchSet) (*table.LargeCommu if err != nil { return nil, err } - c := config.MatchLargeCommunitySet{ + c := oc.MatchLargeCommunitySet{ LargeCommunitySet: a.Name, MatchSetOptions: typ, } @@ -1396,11 +1396,11 @@ func newAfiSafiInConditionFromApiStruct(a []*api.Family) (*table.AfiSafiInCondit if a == nil { return nil, nil } - afiSafiTypes := make([]config.AfiSafiType, 0, len(a)) + afiSafiTypes := make([]oc.AfiSafiType, 0, len(a)) for _, aType := range a { rf := bgp.AfiSafiToRouteFamily(uint16(aType.Afi), uint8(aType.Safi)) if configType, ok := bgp.AddressFamilyNameMap[bgp.RouteFamily(rf)]; ok { - afiSafiTypes = append(afiSafiTypes, config.AfiSafiType(configType)) + afiSafiTypes = append(afiSafiTypes, oc.AfiSafiType(configType)) } else { return nil, fmt.Errorf("unknown afi-safi-in type value: %v", aType) } @@ -1425,9 +1425,9 @@ func newCommunityActionFromApiStruct(a *api.CommunityAction) (*table.CommunityAc if a == nil { return nil, nil } - return table.NewCommunityAction(config.SetCommunity{ - Options: string(config.IntToBgpSetCommunityOptionTypeMap[int(a.Type)]), - SetCommunityMethod: config.SetCommunityMethod{ + return table.NewCommunityAction(oc.SetCommunity{ + Options: string(oc.IntToBgpSetCommunityOptionTypeMap[int(a.Type)]), + SetCommunityMethod: oc.SetCommunityMethod{ CommunitiesList: a.Communities, }, }) @@ -1437,9 +1437,9 @@ func newExtCommunityActionFromApiStruct(a *api.CommunityAction) (*table.ExtCommu if a == nil { return nil, nil } - return table.NewExtCommunityAction(config.SetExtCommunity{ - Options: string(config.IntToBgpSetCommunityOptionTypeMap[int(a.Type)]), - SetExtCommunityMethod: config.SetExtCommunityMethod{ + return table.NewExtCommunityAction(oc.SetExtCommunity{ + Options: string(oc.IntToBgpSetCommunityOptionTypeMap[int(a.Type)]), + SetExtCommunityMethod: oc.SetExtCommunityMethod{ CommunitiesList: a.Communities, }, }) @@ -1449,9 +1449,9 @@ func newLargeCommunityActionFromApiStruct(a *api.CommunityAction) (*table.LargeC if a == nil { return nil, nil } - return table.NewLargeCommunityAction(config.SetLargeCommunity{ - Options: config.IntToBgpSetCommunityOptionTypeMap[int(a.Type)], - SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + return table.NewLargeCommunityAction(oc.SetLargeCommunity{ + Options: oc.IntToBgpSetCommunityOptionTypeMap[int(a.Type)], + SetLargeCommunityMethod: oc.SetLargeCommunityMethod{ CommunitiesList: a.Communities, }, }) @@ -1475,7 +1475,7 @@ func newAsPathPrependActionFromApiStruct(a *api.AsPrependAction) (*table.AsPathP if a == nil { return nil, nil } - return table.NewAsPathPrependAction(config.SetAsPathPrepend{ + return table.NewAsPathPrependAction(oc.SetAsPathPrepend{ RepeatN: uint8(a.Repeat), As: func() string { if a.UseLeftMost { @@ -1490,7 +1490,7 @@ func newNexthopActionFromApiStruct(a *api.NexthopAction) (*table.NexthopAction, if a == nil { return nil, nil } - return table.NewNexthopAction(config.BgpNextHopType( + return table.NewNexthopAction(oc.BgpNextHopType( func() string { if a.Self { return "self" @@ -1624,11 +1624,11 @@ func (s *server) DeleteStatement(ctx context.Context, r *api.DeleteStatementRequ return &emptypb.Empty{}, s.bgpServer.DeleteStatement(ctx, r) } -func newConfigPolicyFromApiStruct(a *api.Policy) (*config.PolicyDefinition, error) { +func newConfigPolicyFromApiStruct(a *api.Policy) (*oc.PolicyDefinition, error) { if a.Name == "" { return nil, fmt.Errorf("empty policy name") } - stmts := make([]config.Statement, 0, len(a.Statements)) + stmts := make([]oc.Statement, 0, len(a.Statements)) for idx, x := range a.Statements { if x.Name == "" { x.Name = fmt.Sprintf("%s_stmt%d", a.Name, idx) @@ -1640,7 +1640,7 @@ func newConfigPolicyFromApiStruct(a *api.Policy) (*config.PolicyDefinition, erro stmt := y.ToConfig() stmts = append(stmts, *stmt) } - return &config.PolicyDefinition{ + return &oc.PolicyDefinition{ Name: a.Name, Statements: stmts, }, nil @@ -1728,10 +1728,10 @@ func defaultRouteType(d api.RouteAction) table.RouteType { } } -func toPolicyDefinition(policies []*api.Policy) []*config.PolicyDefinition { - l := make([]*config.PolicyDefinition, 0, len(policies)) +func toPolicyDefinition(policies []*api.Policy) []*oc.PolicyDefinition { + l := make([]*oc.PolicyDefinition, 0, len(policies)) for _, p := range policies { - l = append(l, &config.PolicyDefinition{Name: p.Name}) + l = append(l, &oc.PolicyDefinition{Name: p.Name}) } return l } @@ -1752,17 +1752,17 @@ func (s *server) GetBgp(ctx context.Context, r *api.GetBgpRequest) (*api.GetBgpR return s.bgpServer.GetBgp(ctx, r) } -func newGlobalFromAPIStruct(a *api.Global) *config.Global { - families := make([]config.AfiSafi, 0, len(a.Families)) +func newGlobalFromAPIStruct(a *api.Global) *oc.Global { + families := make([]oc.AfiSafi, 0, len(a.Families)) for _, f := range a.Families { - name := config.IntToAfiSafiTypeMap[int(f)] + name := oc.IntToAfiSafiTypeMap[int(f)] rf, _ := bgp.GetRouteFamily(string(name)) - families = append(families, config.AfiSafi{ - Config: config.AfiSafiConfig{ + families = append(families, oc.AfiSafi{ + Config: oc.AfiSafiConfig{ AfiSafiName: name, Enabled: true, }, - State: config.AfiSafiState{ + State: oc.AfiSafiState{ AfiSafiName: name, Enabled: true, Family: rf, @@ -1770,11 +1770,11 @@ func newGlobalFromAPIStruct(a *api.Global) *config.Global { }) } - applyPolicy := &config.ApplyPolicy{} + applyPolicy := &oc.ApplyPolicy{} readApplyPolicyFromAPIStruct(applyPolicy, a.ApplyPolicy) - global := &config.Global{ - Config: config.GlobalConfig{ + global := &oc.Global{ + Config: oc.GlobalConfig{ As: a.Asn, RouterId: a.RouterId, Port: a.ListenPort, @@ -1782,15 +1782,15 @@ func newGlobalFromAPIStruct(a *api.Global) *config.Global { }, ApplyPolicy: *applyPolicy, AfiSafis: families, - UseMultiplePaths: config.UseMultiplePaths{ - Config: config.UseMultiplePathsConfig{ + UseMultiplePaths: oc.UseMultiplePaths{ + Config: oc.UseMultiplePathsConfig{ Enabled: a.UseMultiplePaths, }, }, } if a.RouteSelectionOptions != nil { - global.RouteSelectionOptions = config.RouteSelectionOptions{ - Config: config.RouteSelectionOptionsConfig{ + global.RouteSelectionOptions = oc.RouteSelectionOptions{ + Config: oc.RouteSelectionOptionsConfig{ AlwaysCompareMed: a.RouteSelectionOptions.AlwaysCompareMed, IgnoreAsPathLength: a.RouteSelectionOptions.IgnoreAsPathLength, ExternalCompareRouterId: a.RouteSelectionOptions.ExternalCompareRouterId, @@ -1802,16 +1802,16 @@ func newGlobalFromAPIStruct(a *api.Global) *config.Global { } } if a.DefaultRouteDistance != nil { - global.DefaultRouteDistance = config.DefaultRouteDistance{ - Config: config.DefaultRouteDistanceConfig{ + global.DefaultRouteDistance = oc.DefaultRouteDistance{ + Config: oc.DefaultRouteDistanceConfig{ ExternalRouteDistance: uint8(a.DefaultRouteDistance.ExternalRouteDistance), InternalRouteDistance: uint8(a.DefaultRouteDistance.InternalRouteDistance), }, } } if a.Confederation != nil { - global.Confederation = config.Confederation{ - Config: config.ConfederationConfig{ + global.Confederation = oc.Confederation{ + Config: oc.ConfederationConfig{ Enabled: a.Confederation.Enabled, Identifier: a.Confederation.Identifier, MemberAsList: a.Confederation.MemberAsList, @@ -1819,8 +1819,8 @@ func newGlobalFromAPIStruct(a *api.Global) *config.Global { } } if a.GracefulRestart != nil { - global.GracefulRestart = config.GracefulRestart{ - Config: config.GracefulRestartConfig{ + global.GracefulRestart = oc.GracefulRestart{ + Config: oc.GracefulRestartConfig{ Enabled: a.GracefulRestart.Enabled, RestartTime: uint16(a.GracefulRestart.RestartTime), StaleRoutesTime: float64(a.GracefulRestart.StaleRoutesTime), diff --git a/pkg/server/mrt.go b/pkg/server/mrt.go index bd992f805..2e2a3aa97 100644 --- a/pkg/server/mrt.go +++ b/pkg/server/mrt.go @@ -21,8 +21,8 @@ import ( "os" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/osrg/gobgp/v3/pkg/packet/mrt" @@ -36,7 +36,7 @@ const ( type mrtWriter struct { dead chan struct{} s *BgpServer - c *config.MrtConfig + c *oc.MrtConfig file *os.File rotationInterval uint64 dumpInterval uint64 @@ -49,9 +49,9 @@ func (m *mrtWriter) Stop() { func (m *mrtWriter) loop() error { ops := []watchOption{} switch m.c.DumpType { - case config.MRT_TYPE_UPDATES: + case oc.MRT_TYPE_UPDATES: ops = append(ops, watchUpdate(false, "", "")) - case config.MRT_TYPE_TABLE: + case oc.MRT_TYPE_TABLE: if len(m.c.TableName) > 0 { ops = append(ops, watchTableName(m.c.TableName)) } @@ -119,7 +119,7 @@ func (m *mrtWriter) loop() error { peers := make([]*mrt.Peer, 1, len(e.Neighbor)+1) // Adding dummy Peer record for locally generated routes peers[0] = mrt.NewPeer("0.0.0.0", "0.0.0.0", 0, true) - neighborMap := make(map[string]*config.Neighbor) + neighborMap := make(map[string]*oc.Neighbor) for _, pconf := range e.Neighbor { peers = append(peers, mrt.NewPeer(pconf.State.RemoteRouterId, pconf.State.NeighborAddress, pconf.Config.PeerAs, true)) neighborMap[pconf.State.NeighborAddress] = pconf @@ -269,11 +269,11 @@ func (m *mrtWriter) loop() error { return nil case e := <-w.Event(): drain(e) - if m.c.DumpType == config.MRT_TYPE_TABLE && m.rotationInterval != 0 { + if m.c.DumpType == oc.MRT_TYPE_TABLE && m.rotationInterval != 0 { rotate() } case <-rotator.C: - if m.c.DumpType == config.MRT_TYPE_UPDATES { + if m.c.DumpType == oc.MRT_TYPE_UPDATES { rotate() } else { w.Generate(watchEventTypeTable) @@ -326,7 +326,7 @@ func mrtFileOpen(logger log.Logger, filename string, rInterval uint64) (*os.File return file, err } -func newMrtWriter(s *BgpServer, c *config.MrtConfig, rInterval, dInterval uint64) (*mrtWriter, error) { +func newMrtWriter(s *BgpServer, c *oc.MrtConfig, rInterval, dInterval uint64) (*mrtWriter, error) { file, err := mrtFileOpen(s.logger, c.FileName, rInterval) if err != nil { return nil, err @@ -347,7 +347,7 @@ type mrtManager struct { writer map[string]*mrtWriter } -func (m *mrtManager) enable(c *config.MrtConfig) error { +func (m *mrtManager) enable(c *oc.MrtConfig) error { if _, ok := m.writer[c.FileName]; ok { return fmt.Errorf("%s already exists", c.FileName) } @@ -365,7 +365,7 @@ func (m *mrtManager) enable(c *config.MrtConfig) error { } } - if c.DumpType == config.MRT_TYPE_TABLE { + if c.DumpType == oc.MRT_TYPE_TABLE { if rInterval == 0 { if dInterval < minDumpInterval { m.bgpServer.logger.Info("use minimum mrt dump interval", @@ -379,7 +379,7 @@ func (m *mrtManager) enable(c *config.MrtConfig) error { } else { return fmt.Errorf("can't specify both intervals in the table dump type") } - } else if c.DumpType == config.MRT_TYPE_UPDATES { + } else if c.DumpType == oc.MRT_TYPE_UPDATES { // ignore the dump interval dInterval = 0 if len(c.TableName) > 0 { @@ -395,7 +395,7 @@ func (m *mrtManager) enable(c *config.MrtConfig) error { return err } -func (m *mrtManager) disable(c *config.MrtConfig) error { +func (m *mrtManager) disable(c *oc.MrtConfig) error { w, ok := m.writer[c.FileName] if !ok { return fmt.Errorf("%s doesn't exists", c.FileName) diff --git a/pkg/server/peer.go b/pkg/server/peer.go index 5abac0937..ba65f21d3 100644 --- a/pkg/server/peer.go +++ b/pkg/server/peer.go @@ -20,8 +20,8 @@ import ( "net" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -31,28 +31,28 @@ const ( ) type peerGroup struct { - Conf *config.PeerGroup - members map[string]config.Neighbor - dynamicNeighbors map[string]*config.DynamicNeighbor + Conf *oc.PeerGroup + members map[string]oc.Neighbor + dynamicNeighbors map[string]*oc.DynamicNeighbor } -func newPeerGroup(c *config.PeerGroup) *peerGroup { +func newPeerGroup(c *oc.PeerGroup) *peerGroup { return &peerGroup{ Conf: c, - members: make(map[string]config.Neighbor), - dynamicNeighbors: make(map[string]*config.DynamicNeighbor), + members: make(map[string]oc.Neighbor), + dynamicNeighbors: make(map[string]*oc.DynamicNeighbor), } } -func (pg *peerGroup) AddMember(c config.Neighbor) { +func (pg *peerGroup) AddMember(c oc.Neighbor) { pg.members[c.State.NeighborAddress] = c } -func (pg *peerGroup) DeleteMember(c config.Neighbor) { +func (pg *peerGroup) DeleteMember(c oc.Neighbor) { delete(pg.members, c.State.NeighborAddress) } -func (pg *peerGroup) AddDynamicNeighbor(c *config.DynamicNeighbor) { +func (pg *peerGroup) AddDynamicNeighbor(c *oc.DynamicNeighbor) { pg.dynamicNeighbors[c.Config.Prefix] = c } @@ -60,21 +60,21 @@ func (pg *peerGroup) DeleteDynamicNeighbor(prefix string) { delete(pg.dynamicNeighbors, prefix) } -func newDynamicPeer(g *config.Global, neighborAddress string, pg *config.PeerGroup, loc *table.TableManager, policy *table.RoutingPolicy, logger log.Logger) *peer { - conf := config.Neighbor{ - Config: config.NeighborConfig{ +func newDynamicPeer(g *oc.Global, neighborAddress string, pg *oc.PeerGroup, loc *table.TableManager, policy *table.RoutingPolicy, logger log.Logger) *peer { + conf := oc.Neighbor{ + Config: oc.NeighborConfig{ PeerGroup: pg.Config.PeerGroupName, }, - State: config.NeighborState{ + State: oc.NeighborState{ NeighborAddress: neighborAddress, }, - Transport: config.Transport{ - Config: config.TransportConfig{ + Transport: oc.Transport{ + Config: oc.TransportConfig{ PassiveMode: true, }, }, } - if err := config.OverwriteNeighborConfigWithPeerGroup(&conf, pg); err != nil { + if err := oc.OverwriteNeighborConfigWithPeerGroup(&conf, pg); err != nil { logger.Debug("Can't overwrite neighbor config", log.Fields{ "Topic": "Peer", @@ -82,7 +82,7 @@ func newDynamicPeer(g *config.Global, neighborAddress string, pg *config.PeerGro "Error": err}) return nil } - if err := config.SetDefaultNeighborConfigValues(&conf, pg, g); err != nil { + if err := oc.SetDefaultNeighborConfigValues(&conf, pg, g); err != nil { logger.Debug("Can't set default config", log.Fields{ "Topic": "Peer", @@ -107,7 +107,7 @@ type peer struct { llgrEndChs []chan struct{} } -func newPeer(g *config.Global, conf *config.Neighbor, loc *table.TableManager, policy *table.RoutingPolicy, logger log.Logger) *peer { +func newPeer(g *oc.Global, conf *oc.Neighbor, loc *table.TableManager, policy *table.RoutingPolicy, logger log.Logger) *peer { peer := &peer{ localRib: loc, policy: policy, @@ -119,7 +119,7 @@ func newPeer(g *config.Global, conf *config.Neighbor, loc *table.TableManager, p } else { peer.tableId = table.GLOBAL_RIB_NAME } - rfs, _ := config.AfiSafis(conf.AfiSafis).ToRfList() + rfs, _ := oc.AfiSafis(conf.AfiSafis).ToRfList() peer.adjRibIn = table.NewAdjRib(peer.fsm.logger, rfs) return peer } @@ -152,7 +152,7 @@ func (peer *peer) TableID() string { func (peer *peer) isIBGPPeer() bool { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() - return peer.fsm.pConf.State.PeerType == config.PEER_TYPE_INTERNAL + return peer.fsm.pConf.State.PeerType == oc.PEER_TYPE_INTERNAL } func (peer *peer) isRouteServerClient() bool { @@ -216,7 +216,7 @@ func (peer *peer) recvedAllEOR() bool { func (peer *peer) configuredRFlist() []bgp.RouteFamily { peer.fsm.lock.RLock() defer peer.fsm.lock.RUnlock() - rfs, _ := config.AfiSafis(peer.fsm.pConf.AfiSafis).ToRfList() + rfs, _ := oc.AfiSafis(peer.fsm.pConf.AfiSafis).ToRfList() return rfs } @@ -411,7 +411,7 @@ func (peer *peer) filterPathFromSourcePeer(path, old *table.Path) *table.Path { return nil } -func (peer *peer) doPrefixLimit(k bgp.RouteFamily, c *config.PrefixLimitConfig) *bgp.BGPMessage { +func (peer *peer) doPrefixLimit(k bgp.RouteFamily, c *oc.PrefixLimitConfig) *bgp.BGPMessage { if maxPrefixes := int(c.MaxPrefixes); maxPrefixes > 0 { count := peer.adjRibIn.Count([]bgp.RouteFamily{k}) pct := int(c.ShutdownThresholdPct) @@ -437,7 +437,7 @@ func (peer *peer) doPrefixLimit(k bgp.RouteFamily, c *config.PrefixLimitConfig) } -func (peer *peer) updatePrefixLimitConfig(c []config.AfiSafi) error { +func (peer *peer) updatePrefixLimitConfig(c []oc.AfiSafi) error { peer.fsm.lock.RLock() x := peer.fsm.pConf.AfiSafis peer.fsm.lock.RUnlock() @@ -445,7 +445,7 @@ func (peer *peer) updatePrefixLimitConfig(c []config.AfiSafi) error { if len(x) != len(y) { return fmt.Errorf("changing supported afi-safi is not allowed") } - m := make(map[bgp.RouteFamily]config.PrefixLimitConfig) + m := make(map[bgp.RouteFamily]oc.PrefixLimitConfig) for _, e := range x { m[e.State.Family] = e.PrefixLimit.Config } diff --git a/pkg/server/rpki.go b/pkg/server/rpki.go index 75e2a354b..4b78f07bf 100644 --- a/pkg/server/rpki.go +++ b/pkg/server/rpki.go @@ -24,8 +24,8 @@ import ( "strconv" "time" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/osrg/gobgp/v3/pkg/packet/rtr" @@ -174,7 +174,7 @@ func (m *roaManager) HandleROAEvent(ev *roaEvent) { // clear state client.endOfData = false client.pendingROAs = make([]*table.ROA, 0) - client.state.RpkiMessages = config.RpkiMessages{} + client.state.RpkiMessages = oc.RpkiMessages{} client.conn = nil go client.tryConnect() client.timer = time.AfterFunc(time.Duration(client.lifetime)*time.Second, client.lifetimeout) @@ -212,7 +212,7 @@ func (m *roaManager) HandleROAEvent(ev *roaEvent) { } } -func (m *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerState, buf []byte) { +func (m *roaManager) handleRTRMsg(client *roaClient, state *oc.RpkiServerState, buf []byte) { received := &state.RpkiMessages.RpkiReceived m1, err := rtr.ParseRTR(buf) @@ -284,11 +284,11 @@ func (m *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta } } -func (m *roaManager) GetServers() []*config.RpkiServer { +func (m *roaManager) GetServers() []*oc.RpkiServer { recordsV4, prefixesV4 := m.table.Info(bgp.RF_IPv4_UC) recordsV6, prefixesV6 := m.table.Info(bgp.RF_IPv6_UC) - l := make([]*config.RpkiServer, 0, len(m.clientMap)) + l := make([]*oc.RpkiServer, 0, len(m.clientMap)) for _, client := range m.clientMap { state := &client.state @@ -310,8 +310,8 @@ func (m *roaManager) GetServers() []*config.RpkiServer { state.SerialNumber = client.serialNumber addr, port, _ := net.SplitHostPort(client.host) - l = append(l, &config.RpkiServer{ - Config: config.RpkiServerConfig{ + l = append(l, &oc.RpkiServer{ + Config: oc.RpkiServerConfig{ Address: addr, // Note: RpkiServerConfig.Port is uint32 type, but the TCP/UDP // port is 16-bit length. @@ -326,7 +326,7 @@ func (m *roaManager) GetServers() []*config.RpkiServer { type roaClient struct { host string conn *net.TCPConn - state config.RpkiServerState + state oc.RpkiServerState eventCh chan *roaEvent sessionID uint16 oldSessionID uint16 diff --git a/pkg/server/server.go b/pkg/server/server.go index 992c03766..2b3cbcb02 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -33,11 +33,11 @@ import ( "google.golang.org/grpc" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" "github.com/osrg/gobgp/v3/internal/pkg/version" "github.com/osrg/gobgp/v3/internal/pkg/zebra" "github.com/osrg/gobgp/v3/pkg/apiutil" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" "github.com/osrg/gobgp/v3/pkg/packet/bmp" @@ -157,7 +157,7 @@ func LoggerOption(logger log.Logger) ServerOption { type BgpServer struct { apiServer *server - bgpConfig config.Bgp + bgpConfig oc.Bgp acceptCh chan *net.TCPConn incomings []*channels.InfiniteChannel mgmtCh chan *mgmtOp @@ -801,7 +801,7 @@ func (s *BgpServer) notifyBestWatcher(best []*table.Path, multipath [][]*table.P s.notifyWatcher(watchEventTypeBestPath, w) } -func (s *BgpServer) toConfig(peer *peer, getAdvertised bool) *config.Neighbor { +func (s *BgpServer) toConfig(peer *peer, getAdvertised bool) *oc.Neighbor { // create copy which can be access to without mutex peer.fsm.lock.RLock() conf := *peer.fsm.pConf @@ -809,7 +809,7 @@ func (s *BgpServer) toConfig(peer *peer, getAdvertised bool) *config.Neighbor { peerCapMap := peer.fsm.capMap peer.fsm.lock.RUnlock() - conf.AfiSafis = make([]config.AfiSafi, len(peerAfiSafis)) + conf.AfiSafis = make([]oc.AfiSafi, len(peerAfiSafis)) for i, af := range peerAfiSafis { conf.AfiSafis[i] = af conf.AfiSafis[i].AddPaths.State.Receive = peer.isAddPathReceiveEnabled(af.State.Family) @@ -834,8 +834,8 @@ func (s *BgpServer) toConfig(peer *peer, getAdvertised bool) *config.Neighbor { peer.fsm.lock.RLock() conf.State.LocalCapabilityList = capabilitiesFromConfig(peer.fsm.pConf) - conf.State.SessionState = config.IntToSessionStateMap[int(peer.fsm.state)] - conf.State.AdminState = config.IntToAdminStateMap[int(peer.fsm.adminState)] + conf.State.SessionState = oc.IntToSessionStateMap[int(peer.fsm.state)] + conf.State.AdminState = oc.IntToAdminStateMap[int(peer.fsm.adminState)] state := peer.fsm.state peer.fsm.lock.RUnlock() @@ -1367,7 +1367,7 @@ func (s *BgpServer) handleFSMMessage(peer *peer, e *fsmMsg) { nextState := e.MsgData.(bgp.FSMState) peer.fsm.lock.Lock() oldState := bgp.FSMState(peer.fsm.pConf.State.SessionState.ToInt()) - peer.fsm.pConf.State.SessionState = config.IntToSessionStateMap[int(nextState)] + peer.fsm.pConf.State.SessionState = oc.IntToSessionStateMap[int(nextState)] peer.fsm.lock.Unlock() peer.fsm.StateChange(nextState) @@ -1611,10 +1611,10 @@ func (s *BgpServer) handleFSMMessage(peer *peer, e *fsmMsg) { peer.fsm.lock.RUnlock() if adminStateDown { peer.fsm.lock.Lock() - peer.fsm.pConf.State = config.NeighborState{} + peer.fsm.pConf.State = oc.NeighborState{} peer.fsm.pConf.State.NeighborAddress = peer.fsm.pConf.Config.NeighborAddress peer.fsm.pConf.State.PeerAs = peer.fsm.pConf.Config.PeerAs - peer.fsm.pConf.Timers.State = config.TimersState{} + peer.fsm.pConf.Timers.State = oc.TimersState{} peer.fsm.lock.Unlock() } peer.startFSMHandler() @@ -1816,12 +1816,12 @@ func (s *BgpServer) AddBmp(ctx context.Context, r *api.AddBmpRequest) error { sysDescr = version.Version() } s.logger.Debug("add bmp server", log.Fields{"address": r.Address, "port": r.Port, "policy": r.Policy}) - return s.bmpManager.addServer(&config.BmpServerConfig{ + return s.bmpManager.addServer(&oc.BmpServerConfig{ Address: r.Address, Port: port, SysName: sysname, SysDescr: sysDescr, - RouteMonitoringPolicy: config.IntToBmpRouteMonitoringPolicyTypeMap[int(r.Policy)], + RouteMonitoringPolicy: oc.IntToBmpRouteMonitoringPolicyTypeMap[int(r.Policy)], StatisticsTimeout: uint16(r.StatisticsTimeout), }) }, true) @@ -1832,7 +1832,7 @@ func (s *BgpServer) DeleteBmp(ctx context.Context, r *api.DeleteBmpRequest) erro return fmt.Errorf("nil request") } return s.mgmtOperation(func() error { - return s.bmpManager.deleteServer(&config.BmpServerConfig{ + return s.bmpManager.deleteServer(&oc.BmpServerConfig{ Address: r.Address, Port: r.Port, }) @@ -1852,8 +1852,8 @@ func (s *BgpServer) ListBmp(ctx context.Context, req *api.ListBmpRequest, fn fun Port: s.c.Port, }, State: &api.ListBmpResponse_BmpStation_State{ - Uptime: config.ProtoTimestamp(atomic.LoadInt64(&s.uptime)), - Downtime: config.ProtoTimestamp(atomic.LoadInt64(&s.downtime)), + Uptime: oc.ProtoTimestamp(atomic.LoadInt64(&s.uptime)), + Downtime: oc.ProtoTimestamp(atomic.LoadInt64(&s.downtime)), }, }) } @@ -1887,7 +1887,7 @@ func (s *BgpServer) StopBgp(ctx context.Context, r *api.StopBgpRequest) error { s.shutdownWG.Add(1) } for _, name := range names { - if err := s.deleteNeighbor(&config.Neighbor{Config: config.NeighborConfig{ + if err := s.deleteNeighbor(&oc.Neighbor{Config: oc.NeighborConfig{ NeighborAddress: name}}, bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_PEER_DECONFIGURED); err != nil { return err } @@ -1895,7 +1895,7 @@ func (s *BgpServer) StopBgp(ctx context.Context, r *api.StopBgpRequest) error { for _, l := range s.listeners { l.Close() } - s.bgpConfig.Global = config.Global{} + s.bgpConfig.Global = oc.Global{} return nil }, false) @@ -1915,24 +1915,24 @@ func (s *BgpServer) SetPolicies(ctx context.Context, r *api.SetPoliciesRequest) return err } - getConfig := func(id string) (*config.ApplyPolicy, error) { - f := func(id string, dir table.PolicyDirection) (config.DefaultPolicyType, []string, error) { + getConfig := func(id string) (*oc.ApplyPolicy, error) { + f := func(id string, dir table.PolicyDirection) (oc.DefaultPolicyType, []string, error) { rt, policies, err := s.policy.GetPolicyAssignment(id, dir) if err != nil { - return config.DEFAULT_POLICY_TYPE_REJECT_ROUTE, nil, err + return oc.DEFAULT_POLICY_TYPE_REJECT_ROUTE, nil, err } names := make([]string, 0, len(policies)) for _, p := range policies { names = append(names, p.Name) } - t := config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE + t := oc.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE if rt == table.ROUTE_TYPE_REJECT { - t = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE + t = oc.DEFAULT_POLICY_TYPE_REJECT_ROUTE } return t, names, nil } - c := &config.ApplyPolicy{} + c := &oc.ApplyPolicy{} rt, policies, err := f(id, table.POLICY_DIRECTION_IMPORT) if err != nil { return nil, err @@ -1949,7 +1949,7 @@ func (s *BgpServer) SetPolicies(ctx context.Context, r *api.SetPoliciesRequest) } return s.mgmtOperation(func() error { - ap := make(map[string]config.ApplyPolicy, len(s.neighborMap)+1) + ap := make(map[string]oc.ApplyPolicy, len(s.neighborMap)+1) a, err := getConfig(table.GLOBAL_RIB_NAME) if err != nil { return err @@ -2238,7 +2238,7 @@ func (s *BgpServer) StartBgp(ctx context.Context, r *api.StartBgpRequest) error } c := newGlobalFromAPIStruct(g) - if err := config.SetDefaultGlobalConfigValues(c); err != nil { + if err := oc.SetDefaultGlobalConfigValues(c); err != nil { return err } @@ -2254,7 +2254,7 @@ func (s *BgpServer) StartBgp(ctx context.Context, r *api.StartBgpRequest) error s.acceptCh = acceptCh } - rfs, _ := config.AfiSafis(c.AfiSafis).ToRfList() + rfs, _ := oc.AfiSafis(c.AfiSafis).ToRfList() s.globalRib = table.NewTableManager(s.logger, rfs) s.rsRib = table.NewTableManager(s.logger, rfs) @@ -2856,7 +2856,7 @@ func (s *BgpServer) ListDynamicNeighbor(ctx context.Context, r *api.ListDynamicN if r == nil { return fmt.Errorf("nil request") } - toApi := func(dn *config.DynamicNeighbor) *api.DynamicNeighbor { + toApi := func(dn *oc.DynamicNeighbor) *api.DynamicNeighbor { return &api.DynamicNeighbor{ Prefix: dn.Config.Prefix, PeerGroup: dn.Config.PeerGroup, @@ -2898,7 +2898,7 @@ func (s *BgpServer) ListPeerGroup(ctx context.Context, r *api.ListPeerGroupReque if peerGroupName != "" && peerGroupName != k { continue } - pg := config.NewPeerGroupFromConfigStruct(group.Conf) + pg := oc.NewPeerGroupFromConfigStruct(group.Conf) l = append(l, pg) } return nil @@ -2931,7 +2931,7 @@ func (s *BgpServer) ListPeer(ctx context.Context, r *api.ListPeerRequest, fn fun continue } // FIXME: should remove toConfig() conversion - p := config.NewPeerFromConfigStruct(s.toConfig(peer, getAdvertised)) + p := oc.NewPeerFromConfigStruct(s.toConfig(peer, getAdvertised)) for _, family := range peer.configuredRFlist() { for i, afisafi := range p.AfiSafis { if !afisafi.Config.Enabled { @@ -2973,7 +2973,7 @@ func (s *BgpServer) ListPeer(ctx context.Context, r *api.ListPeerRequest, fn fun return nil } -func (s *BgpServer) addPeerGroup(c *config.PeerGroup) error { +func (s *BgpServer) addPeerGroup(c *oc.PeerGroup) error { name := c.Config.PeerGroupName if _, y := s.peerGroupMap[name]; y { return fmt.Errorf("can't overwrite the existing peer-group: %s", name) @@ -2989,7 +2989,7 @@ func (s *BgpServer) addPeerGroup(c *config.PeerGroup) error { return nil } -func (s *BgpServer) addNeighbor(c *config.Neighbor) error { +func (s *BgpServer) addNeighbor(c *oc.Neighbor) error { addr, err := c.ExtractNeighborAddress() if err != nil { return err @@ -2999,7 +2999,7 @@ func (s *BgpServer) addNeighbor(c *config.Neighbor) error { return fmt.Errorf("can't overwrite the existing peer: %s", addr) } - var pgConf *config.PeerGroup + var pgConf *oc.PeerGroup if c.Config.PeerGroup != "" { pg, ok := s.peerGroupMap[c.Config.PeerGroup] if !ok { @@ -3008,7 +3008,7 @@ func (s *BgpServer) addNeighbor(c *config.Neighbor) error { pgConf = pg.Conf } - if err := config.SetDefaultNeighborConfigValues(c, pgConf, &s.bgpConfig.Global); err != nil { + if err := oc.SetDefaultNeighborConfigValues(c, pgConf, &s.bgpConfig.Global); err != nil { return err } @@ -3016,7 +3016,7 @@ func (s *BgpServer) addNeighbor(c *config.Neighbor) error { if c.RouteServer.Config.RouteServerClient { return fmt.Errorf("route server client can't be enslaved to VRF") } - families, _ := config.AfiSafis(c.AfiSafis).ToRfList() + families, _ := oc.AfiSafis(c.AfiSafis).ToRfList() for _, f := range families { if f != bgp.RF_IPv4_UC && f != bgp.RF_IPv6_UC && f != bgp.RF_FS_IPv4_UC && f != bgp.RF_FS_IPv6_UC { return fmt.Errorf("%s is not supported for VRF enslaved neighbor", f) @@ -3097,7 +3097,7 @@ func (s *BgpServer) AddDynamicNeighbor(ctx context.Context, r *api.AddDynamicNei return fmt.Errorf("nil request") } return s.mgmtOperation(func() error { - c := &config.DynamicNeighbor{Config: config.DynamicNeighborConfig{ + c := &oc.DynamicNeighbor{Config: oc.DynamicNeighborConfig{ Prefix: r.DynamicNeighbor.Prefix, PeerGroup: r.DynamicNeighbor.PeerGroup}, } @@ -3120,7 +3120,7 @@ func (s *BgpServer) deletePeerGroup(name string) error { return nil } -func (s *BgpServer) deleteNeighbor(c *config.Neighbor, code, subcode uint8) error { +func (s *BgpServer) deleteNeighbor(c *oc.Neighbor, code, subcode uint8) error { if c.Config.PeerGroup != "" { _, y := s.peerGroupMap[c.Config.PeerGroup] if y { @@ -3135,7 +3135,7 @@ func (s *BgpServer) deleteNeighbor(c *config.Neighbor, code, subcode uint8) erro if intf := c.Config.NeighborInterface; intf != "" { var err error - addr, err = config.GetIPv6LinkLocalNeighborAddress(intf) + addr, err = oc.GetIPv6LinkLocalNeighborAddress(intf) if err != nil { return err } @@ -3192,7 +3192,7 @@ func (s *BgpServer) DeletePeer(ctx context.Context, r *api.DeletePeerRequest) er return fmt.Errorf("nil request") } return s.mgmtOperation(func() error { - c := &config.Neighbor{Config: config.NeighborConfig{ + c := &oc.Neighbor{Config: oc.NeighborConfig{ NeighborAddress: r.Address, NeighborInterface: r.Interface, }} @@ -3210,7 +3210,7 @@ func (s *BgpServer) DeleteDynamicNeighbor(ctx context.Context, r *api.DeleteDyna }, true) } -func (s *BgpServer) updatePeerGroup(pg *config.PeerGroup) (needsSoftResetIn bool, err error) { +func (s *BgpServer) updatePeerGroup(pg *oc.PeerGroup) (needsSoftResetIn bool, err error) { name := pg.Config.PeerGroupName _, ok := s.peerGroupMap[name] @@ -3246,8 +3246,8 @@ func (s *BgpServer) UpdatePeerGroup(ctx context.Context, r *api.UpdatePeerGroupR return &api.UpdatePeerGroupResponse{NeedsSoftResetIn: doSoftreset}, err } -func (s *BgpServer) updateNeighbor(c *config.Neighbor) (needsSoftResetIn bool, err error) { - var pgConf *config.PeerGroup +func (s *BgpServer) updateNeighbor(c *oc.Neighbor) (needsSoftResetIn bool, err error) { + var pgConf *oc.PeerGroup if c.Config.PeerGroup != "" { if pg, ok := s.peerGroupMap[c.Config.PeerGroup]; ok { pgConf = pg.Conf @@ -3255,7 +3255,7 @@ func (s *BgpServer) updateNeighbor(c *config.Neighbor) (needsSoftResetIn bool, e return needsSoftResetIn, fmt.Errorf("no such peer-group: %s", c.Config.PeerGroup) } } - if err := config.SetDefaultNeighborConfigValues(c, pgConf, &s.bgpConfig.Global); err != nil { + if err := oc.SetDefaultNeighborConfigValues(c, pgConf, &s.bgpConfig.Global); err != nil { return needsSoftResetIn, err } @@ -3524,7 +3524,7 @@ func (s *BgpServer) ListDefinedSet(ctx context.Context, r *api.ListDefinedSetReq if r == nil { return fmt.Errorf("nil request") } - var cd *config.DefinedSets + var cd *oc.DefinedSets var err error err = s.mgmtOperation(func() error { cd, err = s.policy.GetDefinedSet(table.DefinedType(r.DefinedType), r.Name) @@ -3879,10 +3879,10 @@ func (s *BgpServer) EnableMrt(ctx context.Context, r *api.EnableMrtRequest) erro return fmt.Errorf("nil request") } return s.mgmtOperation(func() error { - return s.mrtManager.enable(&config.MrtConfig{ + return s.mrtManager.enable(&oc.MrtConfig{ DumpInterval: r.DumpInterval, RotationInterval: r.RotationInterval, - DumpType: config.IntToMrtTypeMap[int(r.Type)], + DumpType: oc.IntToMrtTypeMap[int(r.Type)], FileName: r.Filename, }) }, false) @@ -3893,7 +3893,7 @@ func (s *BgpServer) DisableMrt(ctx context.Context, r *api.DisableMrtRequest) er return fmt.Errorf("nil request") } return s.mgmtOperation(func() error { - return s.mrtManager.disable(&config.MrtConfig{}) + return s.mrtManager.disable(&oc.MrtConfig{}) }, false) } @@ -3912,8 +3912,8 @@ func (s *BgpServer) ListRpki(ctx context.Context, r *api.ListRpkiRequest, fn fun RemotePort: uint32(r.Config.Port), }, State: &api.RPKIState{ - Uptime: config.ProtoTimestamp(r.State.Uptime), - Downtime: config.ProtoTimestamp(r.State.Downtime), + Uptime: oc.ProtoTimestamp(r.State.Uptime), + Downtime: oc.ProtoTimestamp(r.State.Downtime), Up: r.State.Up, RecordIpv4: r.State.RecordsV4, RecordIpv6: r.State.RecordsV6, @@ -4183,7 +4183,7 @@ type watchEventUpdate struct { PostPolicy bool Init bool PathList []*table.Path - Neighbor *config.Neighbor + Neighbor *oc.Neighbor } type PeerEventType uint32 @@ -4221,7 +4221,7 @@ type watchEventAdjIn struct { type watchEventTable struct { RouterID string PathList map[string][]*table.Path - Neighbor []*config.Neighbor + Neighbor []*oc.Neighbor } type watchEventBestPath struct { @@ -4392,7 +4392,7 @@ func (w *watcher) Generate(t watchEventType) error { } return pathList }() - l := make([]*config.Neighbor, 0, len(w.s.neighborMap)) + l := make([]*oc.Neighbor, 0, len(w.s.neighborMap)) for _, peer := range w.s.neighborMap { l = append(l, w.s.toConfig(peer, false)) } @@ -4571,7 +4571,7 @@ func (s *BgpServer) watch(opts ...watchOption) (w *watcher) { } for peerInfo, paths := range pathsByPeer { // create copy which can be access to without mutex - var configNeighbor *config.Neighbor + var configNeighbor *oc.Neighbor peerAddress := peerInfo.Address.String() if peer, ok := s.neighborMap[peerAddress]; ok { configNeighbor = w.s.toConfig(peer, false) diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index e092adc74..9fe43405b 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -31,9 +31,9 @@ import ( apb "google.golang.org/protobuf/types/known/anypb" api "github.com/osrg/gobgp/v3/api" - "github.com/osrg/gobgp/v3/internal/pkg/config" "github.com/osrg/gobgp/v3/internal/pkg/table" "github.com/osrg/gobgp/v3/pkg/apiutil" + "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/osrg/gobgp/v3/pkg/log" "github.com/osrg/gobgp/v3/pkg/packet/bgp" ) @@ -105,7 +105,7 @@ func TestModPolicyAssign(t *testing.T) { err = s.AddPolicy(context.Background(), &api.AddPolicyRequest{Policy: table.NewAPIPolicyFromTableStruct(&table.Policy{Name: "p3"})}) assert.Nil(err) - f := func(l []*config.PolicyDefinition) *api.PolicyAssignment { + f := func(l []*oc.PolicyDefinition) *api.PolicyAssignment { pl := make([]*api.Policy, 0, len(l)) for _, d := range l { pl = append(pl, table.ToPolicyApi(d)) @@ -115,7 +115,7 @@ func TestModPolicyAssign(t *testing.T) { } } - r := f([]*config.PolicyDefinition{{Name: "p1"}, {Name: "p2"}, {Name: "p3"}}) + r := f([]*oc.PolicyDefinition{{Name: "p1"}, {Name: "p2"}, {Name: "p3"}}) r.Direction = api.PolicyDirection_IMPORT r.DefaultAction = api.RouteAction_ACCEPT r.Name = table.GLOBAL_RIB_NAME @@ -133,7 +133,7 @@ func TestModPolicyAssign(t *testing.T) { assert.Nil(err) assert.Equal(len(ps[0].Policies), 3) - r = f([]*config.PolicyDefinition{{Name: "p1"}}) + r = f([]*oc.PolicyDefinition{{Name: "p1"}}) r.Direction = api.PolicyDirection_IMPORT r.DefaultAction = api.RouteAction_ACCEPT r.Name = table.GLOBAL_RIB_NAME @@ -716,13 +716,13 @@ func TestNumGoroutineWithAddDeleteNeighbor(t *testing.T) { } func newPeerandInfo(myAs, as uint32, address string, rib *table.TableManager) (*peer, *table.PeerInfo) { - nConf := &config.Neighbor{Config: config.NeighborConfig{PeerAs: as, NeighborAddress: address}} - gConf := &config.Global{Config: config.GlobalConfig{As: myAs}} - config.SetDefaultNeighborConfigValues(nConf, nil, gConf) + nConf := &oc.Neighbor{Config: oc.NeighborConfig{PeerAs: as, NeighborAddress: address}} + gConf := &oc.Global{Config: oc.GlobalConfig{As: myAs}} + oc.SetDefaultNeighborConfigValues(nConf, nil, gConf) policy := table.NewRoutingPolicy(logger) - policy.Reset(&config.RoutingPolicy{}, nil) + policy.Reset(&oc.RoutingPolicy{}, nil) p := newPeer( - &config.Global{Config: config.GlobalConfig{As: myAs}}, + &oc.Global{Config: oc.GlobalConfig{As: myAs}}, nConf, rib, policy, @@ -825,33 +825,33 @@ func TestFilterpathWithRejectPolicy(t *testing.T) { rib2 := table.NewTableManager(logger, []bgp.RouteFamily{bgp.RF_IPv4_UC}) p2, _ := newPeerandInfo(1, 3, "192.168.0.2", rib2) - comSet1 := config.CommunitySet{ + comSet1 := oc.CommunitySet{ CommunitySetName: "comset1", CommunityList: []string{"100:100"}, } s, _ := table.NewCommunitySet(comSet1) p2.policy.AddDefinedSet(s) - statement := config.Statement{ + statement := oc.Statement{ Name: "stmt1", - Conditions: config.Conditions{ - BgpConditions: config.BgpConditions{ - MatchCommunitySet: config.MatchCommunitySet{ + Conditions: oc.Conditions{ + BgpConditions: oc.BgpConditions{ + MatchCommunitySet: oc.MatchCommunitySet{ CommunitySet: "comset1", }, }, }, - Actions: config.Actions{ - RouteDisposition: config.ROUTE_DISPOSITION_REJECT_ROUTE, + Actions: oc.Actions{ + RouteDisposition: oc.ROUTE_DISPOSITION_REJECT_ROUTE, }, } - policy := config.PolicyDefinition{ + policy := oc.PolicyDefinition{ Name: "policy1", - Statements: []config.Statement{statement}, + Statements: []oc.Statement{statement}, } p, _ := table.NewPolicy(policy) p2.policy.AddPolicy(p, false) - policies := []*config.PolicyDefinition{ + policies := []*oc.PolicyDefinition{ { Name: "policy1", }, @@ -893,8 +893,8 @@ func TestPeerGroup(test *testing.T) { assert.Nil(err) defer s.StopBgp(context.Background(), &api.StopBgpRequest{}) - g := &config.PeerGroup{ - Config: config.PeerGroupConfig{ + g := &oc.PeerGroup{ + Config: oc.PeerGroupConfig{ PeerAs: 2, PeerGroupName: "g", }, @@ -902,13 +902,13 @@ func TestPeerGroup(test *testing.T) { err = s.addPeerGroup(g) assert.Nil(err) - n := &config.Neighbor{ - Config: config.NeighborConfig{ + n := &oc.Neighbor{ + Config: oc.NeighborConfig{ NeighborAddress: "127.0.0.1", PeerGroup: "g", }, - Transport: config.Transport{ - Config: config.TransportConfig{ + Transport: oc.Transport{ + Config: oc.TransportConfig{ PassiveMode: true, }, }, @@ -924,8 +924,8 @@ func TestPeerGroup(test *testing.T) { }, }, } - config.RegisterConfiguredFields("127.0.0.1", configured) - err = s.AddPeer(context.Background(), &api.AddPeerRequest{Peer: config.NewPeerFromConfigStruct(n)}) + oc.RegisterConfiguredFields("127.0.0.1", configured) + err = s.AddPeer(context.Background(), &api.AddPeerRequest{Peer: oc.NewPeerFromConfigStruct(n)}) assert.Nil(err) t := NewBgpServer() @@ -940,18 +940,18 @@ func TestPeerGroup(test *testing.T) { assert.Nil(err) defer t.StopBgp(context.Background(), &api.StopBgpRequest{}) - m := &config.Neighbor{ - Config: config.NeighborConfig{ + m := &oc.Neighbor{ + Config: oc.NeighborConfig{ NeighborAddress: "127.0.0.1", PeerAs: 1, }, - Transport: config.Transport{ - Config: config.TransportConfig{ + Transport: oc.Transport{ + Config: oc.TransportConfig{ RemotePort: 10179, }, }, - Timers: config.Timers{ - Config: config.TimersConfig{ + Timers: oc.Timers{ + Config: oc.TimersConfig{ ConnectRetry: 1, IdleHoldTimeAfterReset: 1, }, @@ -959,7 +959,7 @@ func TestPeerGroup(test *testing.T) { } ch := make(chan struct{}) go waitEstablished(s, ch) - err = t.AddPeer(context.Background(), &api.AddPeerRequest{Peer: config.NewPeerFromConfigStruct(m)}) + err = t.AddPeer(context.Background(), &api.AddPeerRequest{Peer: oc.NewPeerFromConfigStruct(m)}) assert.Nil(err) <-ch } @@ -979,8 +979,8 @@ func TestDynamicNeighbor(t *testing.T) { assert.Nil(err) defer s1.StopBgp(context.Background(), &api.StopBgpRequest{}) - g := &config.PeerGroup{ - Config: config.PeerGroupConfig{ + g := &oc.PeerGroup{ + Config: oc.PeerGroupConfig{ PeerAs: 2, PeerGroupName: "g", }, @@ -1009,18 +1009,18 @@ func TestDynamicNeighbor(t *testing.T) { assert.Nil(err) defer s2.StopBgp(context.Background(), &api.StopBgpRequest{}) - m := &config.Neighbor{ - Config: config.NeighborConfig{ + m := &oc.Neighbor{ + Config: oc.NeighborConfig{ NeighborAddress: "127.0.0.1", PeerAs: 1, }, - Transport: config.Transport{ - Config: config.TransportConfig{ + Transport: oc.Transport{ + Config: oc.TransportConfig{ RemotePort: 10179, }, }, - Timers: config.Timers{ - Config: config.TimersConfig{ + Timers: oc.Timers{ + Config: oc.TimersConfig{ ConnectRetry: 1, IdleHoldTimeAfterReset: 1, }, @@ -1028,7 +1028,7 @@ func TestDynamicNeighbor(t *testing.T) { } ch := make(chan struct{}) go waitEstablished(s2, ch) - err = s2.AddPeer(context.Background(), &api.AddPeerRequest{Peer: config.NewPeerFromConfigStruct(m)}) + err = s2.AddPeer(context.Background(), &api.AddPeerRequest{Peer: oc.NewPeerFromConfigStruct(m)}) assert.Nil(err) <-ch } @@ -1142,17 +1142,17 @@ func TestGracefulRestartTimerExpired(t *testing.T) { } func TestFamiliesForSoftreset(t *testing.T) { - f := func(f bgp.RouteFamily) config.AfiSafi { - return config.AfiSafi{ - State: config.AfiSafiState{ + f := func(f bgp.RouteFamily) oc.AfiSafi { + return oc.AfiSafi{ + State: oc.AfiSafiState{ Family: f, }, } } peer := &peer{ fsm: &fsm{ - pConf: &config.Neighbor{ - AfiSafis: []config.AfiSafi{f(bgp.RF_RTC_UC), f(bgp.RF_IPv4_UC), f(bgp.RF_IPv6_UC)}, + pConf: &oc.Neighbor{ + AfiSafis: []oc.AfiSafi{f(bgp.RF_RTC_UC), f(bgp.RF_IPv4_UC), f(bgp.RF_IPv6_UC)}, }, }, } @@ -1185,26 +1185,26 @@ func runNewServer(t *testing.T, as uint32, routerID string, listenPort int32) *B return s } -func peerServers(t *testing.T, ctx context.Context, servers []*BgpServer, families []config.AfiSafiType) error { +func peerServers(t *testing.T, ctx context.Context, servers []*BgpServer, families []oc.AfiSafiType) error { for i, server := range servers { for j, peer := range servers { if i == j { continue } - neighborConfig := &config.Neighbor{ - Config: config.NeighborConfig{ + neighborConfig := &oc.Neighbor{ + Config: oc.NeighborConfig{ NeighborAddress: "127.0.0.1", PeerAs: peer.bgpConfig.Global.Config.As, }, - AfiSafis: config.AfiSafis{}, - Transport: config.Transport{ - Config: config.TransportConfig{ + AfiSafis: oc.AfiSafis{}, + Transport: oc.Transport{ + Config: oc.TransportConfig{ RemotePort: uint16(peer.bgpConfig.Global.Config.Port), }, }, - Timers: config.Timers{ - Config: config.TimersConfig{ + Timers: oc.Timers{ + Config: oc.TimersConfig{ ConnectRetry: 1, IdleHoldTimeAfterReset: 1, }, @@ -1217,15 +1217,15 @@ func peerServers(t *testing.T, ctx context.Context, servers []*BgpServer, famili } for _, family := range families { - neighborConfig.AfiSafis = append(neighborConfig.AfiSafis, config.AfiSafi{ - Config: config.AfiSafiConfig{ + neighborConfig.AfiSafis = append(neighborConfig.AfiSafis, oc.AfiSafi{ + Config: oc.AfiSafiConfig{ AfiSafiName: family, Enabled: true, }, }) } - if err := server.AddPeer(ctx, &api.AddPeerRequest{Peer: config.NewPeerFromConfigStruct(neighborConfig)}); err != nil { + if err := server.AddPeer(ctx, &api.AddPeerRequest{Peer: oc.NewPeerFromConfigStruct(neighborConfig)}); err != nil { t.Fatal(err) } } @@ -1299,7 +1299,7 @@ func TestDoNotReactToDuplicateRTCMemberships(t *testing.T) { addVrf(t, s1, "vrf1", "111:111", []string{"111:111"}, []string{"111:111"}, 1) addVrf(t, s2, "vrf1", "111:111", []string{"111:111"}, []string{"111:111"}, 1) - if err := peerServers(t, ctx, []*BgpServer{s1, s2}, []config.AfiSafiType{config.AFI_SAFI_TYPE_L3VPN_IPV4_UNICAST, config.AFI_SAFI_TYPE_RTC}); err != nil { + if err := peerServers(t, ctx, []*BgpServer{s1, s2}, []oc.AfiSafiType{oc.AFI_SAFI_TYPE_L3VPN_IPV4_UNICAST, oc.AFI_SAFI_TYPE_RTC}); err != nil { t.Fatal(err) } watcher := s1.watch(watchUpdate(true, "", "")) diff --git a/tools/config/example_toml.go b/tools/config/example_toml.go index f378f2042..7fbc7178c 100644 --- a/tools/config/example_toml.go +++ b/tools/config/example_toml.go @@ -5,47 +5,47 @@ import ( "fmt" "github.com/BurntSushi/toml" - "github.com/osrg/gobgp/v3/internal/pkg/config" + "github.com/osrg/gobgp/v3/pkg/config/oc" ) func main() { - b := config.Bgp{ - Global: config.Global{ - Config: config.GlobalConfig{ + b := oc.Bgp{ + Global: oc.Global{ + Config: oc.GlobalConfig{ As: 12332, RouterId: "10.0.0.1", }, }, - Neighbors: []config.Neighbor{ + Neighbors: []oc.Neighbor{ { - Config: config.NeighborConfig{ + Config: oc.NeighborConfig{ PeerAs: 12333, AuthPassword: "apple", NeighborAddress: "192.168.177.33", }, - AfiSafis: []config.AfiSafi{ + AfiSafis: []oc.AfiSafi{ { - Config: config.AfiSafiConfig{ + Config: oc.AfiSafiConfig{ AfiSafiName: "ipv4-unicast", }, }, { - Config: config.AfiSafiConfig{ + Config: oc.AfiSafiConfig{ AfiSafiName: "ipv6-unicast", }, }, }, - ApplyPolicy: config.ApplyPolicy{ + ApplyPolicy: oc.ApplyPolicy{ - Config: config.ApplyPolicyConfig{ + Config: oc.ApplyPolicyConfig{ ImportPolicyList: []string{"pd1"}, - DefaultImportPolicy: config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE, + DefaultImportPolicy: oc.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE, }, }, }, { - Config: config.NeighborConfig{ + Config: oc.NeighborConfig{ PeerAs: 12334, AuthPassword: "orange", NeighborAddress: "192.168.177.32", @@ -53,7 +53,7 @@ func main() { }, { - Config: config.NeighborConfig{ + Config: oc.NeighborConfig{ PeerAs: 12335, AuthPassword: "grape", NeighborAddress: "192.168.177.34", @@ -76,91 +76,91 @@ func main() { fmt.Printf("%v\n", buffer.String()) } -func policy() config.RoutingPolicy { +func policy() oc.RoutingPolicy { - ps := config.PrefixSet{ + ps := oc.PrefixSet{ PrefixSetName: "ps1", - PrefixList: []config.Prefix{ + PrefixList: []oc.Prefix{ { IpPrefix: "10.3.192.0/21", MasklengthRange: "21..24", }}, } - ns := config.NeighborSet{ + ns := oc.NeighborSet{ NeighborSetName: "ns1", NeighborInfoList: []string{"10.0.0.2"}, } - cs := config.CommunitySet{ + cs := oc.CommunitySet{ CommunitySetName: "community1", CommunityList: []string{"65100:10"}, } - ecs := config.ExtCommunitySet{ + ecs := oc.ExtCommunitySet{ ExtCommunitySetName: "ecommunity1", ExtCommunityList: []string{"RT:65001:200"}, } - as := config.AsPathSet{ + as := oc.AsPathSet{ AsPathSetName: "aspath1", AsPathList: []string{"^65100"}, } - bds := config.BgpDefinedSets{ - CommunitySets: []config.CommunitySet{cs}, - ExtCommunitySets: []config.ExtCommunitySet{ecs}, - AsPathSets: []config.AsPathSet{as}, + bds := oc.BgpDefinedSets{ + CommunitySets: []oc.CommunitySet{cs}, + ExtCommunitySets: []oc.ExtCommunitySet{ecs}, + AsPathSets: []oc.AsPathSet{as}, } - ds := config.DefinedSets{ - PrefixSets: []config.PrefixSet{ps}, - NeighborSets: []config.NeighborSet{ns}, + ds := oc.DefinedSets{ + PrefixSets: []oc.PrefixSet{ps}, + NeighborSets: []oc.NeighborSet{ns}, BgpDefinedSets: bds, } - al := config.AsPathLength{ + al := oc.AsPathLength{ Operator: "eq", Value: 2, } - s := config.Statement{ + s := oc.Statement{ Name: "statement1", - Conditions: config.Conditions{ + Conditions: oc.Conditions{ - MatchPrefixSet: config.MatchPrefixSet{ + MatchPrefixSet: oc.MatchPrefixSet{ PrefixSet: "ps1", - MatchSetOptions: config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY, }, - MatchNeighborSet: config.MatchNeighborSet{ + MatchNeighborSet: oc.MatchNeighborSet{ NeighborSet: "ns1", - MatchSetOptions: config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY, }, - BgpConditions: config.BgpConditions{ - MatchCommunitySet: config.MatchCommunitySet{ + BgpConditions: oc.BgpConditions{ + MatchCommunitySet: oc.MatchCommunitySet{ CommunitySet: "community1", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_TYPE_ANY, }, - MatchExtCommunitySet: config.MatchExtCommunitySet{ + MatchExtCommunitySet: oc.MatchExtCommunitySet{ ExtCommunitySet: "ecommunity1", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_TYPE_ANY, }, - MatchAsPathSet: config.MatchAsPathSet{ + MatchAsPathSet: oc.MatchAsPathSet{ AsPathSet: "aspath1", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY, + MatchSetOptions: oc.MATCH_SET_OPTIONS_TYPE_ANY, }, AsPathLength: al, }, }, - Actions: config.Actions{ + Actions: oc.Actions{ RouteDisposition: "reject-route", - BgpActions: config.BgpActions{ - SetCommunity: config.SetCommunity{ - SetCommunityMethod: config.SetCommunityMethod{ + BgpActions: oc.BgpActions{ + SetCommunity: oc.SetCommunity{ + SetCommunityMethod: oc.SetCommunityMethod{ CommunitiesList: []string{"65100:20"}, }, Options: "ADD", @@ -170,14 +170,14 @@ func policy() config.RoutingPolicy { }, } - pd := config.PolicyDefinition{ + pd := oc.PolicyDefinition{ Name: "pd1", - Statements: []config.Statement{s}, + Statements: []oc.Statement{s}, } - p := config.RoutingPolicy{ + p := oc.RoutingPolicy{ DefinedSets: ds, - PolicyDefinitions: []config.PolicyDefinition{pd}, + PolicyDefinitions: []oc.PolicyDefinition{pd}, } return p diff --git a/tools/pyang_plugins/README.md b/tools/pyang_plugins/README.md index 7bcfe4a19..a6f37fe3b 100644 --- a/tools/pyang_plugins/README.md +++ b/tools/pyang_plugins/README.md @@ -37,5 +37,5 @@ $ PYTHONPATH=. ./bin/pyang \ $HOME/public/release/models/bgp/openconfig-bgp.yang \ $HOME/public/release/models/policy/openconfig-routing-policy.yang \ $GOBGP/tools/pyang_plugins/gobgp.yang \ - | gofmt > $GOBGP/internal/pkg/config/bgp_configs.go + | gofmt > $GOBGP/pkg/config/oc/bgp_configs.go ``` diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index a384cc586..1ef317af3 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -769,7 +769,7 @@ def is_translation_required(t): def generate_header(fd): print(_COPYRIGHT_NOTICE, file=fd) - print('package config', file=fd) + print('package oc', file=fd) print('', file=fd) print('import (', file=fd) print('"fmt"', file=fd)