diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-10-28 20:49:10 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-10-28 21:41:11 +0900 |
commit | 3e950780fedccacdd1e1267343b5b9baae204566 (patch) | |
tree | 9ce9e5c038fba363b10763a23f96c08aaf8fd702 /internal/pkg/config | |
parent | 5d7ecf5a9e68bcd1a71bc6468e0075f1f9d028ba (diff) |
move NewAPIRoutingPolicyFromConfigStruct() from server/
The config is an internal package so it should not be exported.
NewAPIPolicyAssignmentFromTableStruct() is approprate for config/.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'internal/pkg/config')
-rw-r--r-- | internal/pkg/config/util.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/internal/pkg/config/util.go b/internal/pkg/config/util.go index 47c7d37f..ed9d3049 100644 --- a/internal/pkg/config/util.go +++ b/internal/pkg/config/util.go @@ -642,3 +642,78 @@ func NewGlobalFromConfigStruct(c *Global) *api.Global { ApplyPolicy: applyPolicy, } } + +func newAPIPrefixFromConfigStruct(c Prefix) (*api.Prefix, error) { + min, max, err := ParseMaskLength(c.IpPrefix, c.MasklengthRange) + if err != nil { + return nil, err + } + return &api.Prefix{ + IpPrefix: c.IpPrefix, + MaskLengthMin: uint32(min), + MaskLengthMax: uint32(max), + }, nil +} + +func NewAPIDefinedSetsFromConfigStruct(t *DefinedSets) ([]*api.DefinedSet, error) { + definedSets := make([]*api.DefinedSet, 0) + + for _, ps := range t.PrefixSets { + prefixes := make([]*api.Prefix, 0) + for _, p := range ps.PrefixList { + ap, err := newAPIPrefixFromConfigStruct(p) + if err != nil { + return nil, err + } + prefixes = append(prefixes, ap) + } + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_PREFIX, + Name: ps.PrefixSetName, + Prefixes: prefixes, + }) + } + + for _, ns := range t.NeighborSets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_NEIGHBOR, + Name: ns.NeighborSetName, + List: ns.NeighborInfoList, + }) + } + + bs := t.BgpDefinedSets + for _, cs := range bs.CommunitySets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_COMMUNITY, + Name: cs.CommunitySetName, + List: cs.CommunityList, + }) + } + + for _, es := range bs.ExtCommunitySets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_EXT_COMMUNITY, + Name: es.ExtCommunitySetName, + List: es.ExtCommunityList, + }) + } + + for _, ls := range bs.LargeCommunitySets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_LARGE_COMMUNITY, + Name: ls.LargeCommunitySetName, + List: ls.LargeCommunityList, + }) + } + + for _, as := range bs.AsPathSets { + definedSets = append(definedSets, &api.DefinedSet{ + Type: api.DefinedType_AS_PATH, + Name: as.AsPathSetName, + List: as.AsPathList, + }) + } + + return definedSets, nil +} |