diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-01-08 14:49:27 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-09 05:17:57 -0800 |
commit | 3bed393b014210f6764778138798c31725839079 (patch) | |
tree | 469607542c5e8291b18de97cbd98737f6d2f66ab /config | |
parent | a0b87f1ddf849cc44a39645fb296bfe2d3a5b287 (diff) |
config: add FromInt() method to config typedef
use for the translation between api structs
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r-- | config/bgp_configs.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go index 42c3e750..6baa8bdd 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -43,6 +43,15 @@ func (v RemovePrivateAsOption) ToInt() int { return -1 } +func (v RemovePrivateAsOption) FromInt(i int) RemovePrivateAsOption { + for j, vv := range []string{"all", "replace"} { + if i == j { + return RemovePrivateAsOption(vv) + } + } + return RemovePrivateAsOption("") +} + func (v RemovePrivateAsOption) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid RemovePrivateAsOption: %s", v) @@ -72,6 +81,15 @@ func (v CommunityType) ToInt() int { return -1 } +func (v CommunityType) FromInt(i int) CommunityType { + for j, vv := range []string{"standard", "extended", "both", "none"} { + if i == j { + return CommunityType(vv) + } + } + return CommunityType("") +} + func (v CommunityType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid CommunityType: %s", v) @@ -102,6 +120,15 @@ func (v PeerTypeDef) ToInt() int { return -1 } +func (v PeerTypeDef) FromInt(i int) PeerTypeDef { + for j, vv := range []string{"internal", "external"} { + if i == j { + return PeerTypeDef(vv) + } + } + return PeerTypeDef("") +} + func (v PeerTypeDef) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid PeerTypeDef: %s", v) @@ -126,6 +153,15 @@ func (v BgpSessionDirection) ToInt() int { return -1 } +func (v BgpSessionDirection) FromInt(i int) BgpSessionDirection { + for j, vv := range []string{"inbound", "outbound"} { + if i == j { + return BgpSessionDirection(vv) + } + } + return BgpSessionDirection("") +} + func (v BgpSessionDirection) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid BgpSessionDirection: %s", v) @@ -150,6 +186,15 @@ func (v MatchSetOptionsRestrictedType) ToInt() int { return -1 } +func (v MatchSetOptionsRestrictedType) FromInt(i int) MatchSetOptionsRestrictedType { + for j, vv := range []string{"any", "invert"} { + if i == j { + return MatchSetOptionsRestrictedType(vv) + } + } + return MatchSetOptionsRestrictedType("") +} + func (v MatchSetOptionsRestrictedType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid MatchSetOptionsRestrictedType: %s", v) @@ -186,6 +231,15 @@ func (v MatchSetOptionsType) ToInt() int { return -1 } +func (v MatchSetOptionsType) FromInt(i int) MatchSetOptionsType { + for j, vv := range []string{"any", "all", "invert"} { + if i == j { + return MatchSetOptionsType(vv) + } + } + return MatchSetOptionsType("") +} + func (v MatchSetOptionsType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid MatchSetOptionsType: %s", v) @@ -224,6 +278,15 @@ func (v DefaultPolicyType) ToInt() int { return -1 } +func (v DefaultPolicyType) FromInt(i int) DefaultPolicyType { + for j, vv := range []string{"accept-route", "reject-route"} { + if i == j { + return DefaultPolicyType(vv) + } + } + return DefaultPolicyType("") +} + func (v DefaultPolicyType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid DefaultPolicyType: %s", v) @@ -258,6 +321,15 @@ func (v BgpSetCommunityOptionType) ToInt() int { return -1 } +func (v BgpSetCommunityOptionType) FromInt(i int) BgpSetCommunityOptionType { + for j, vv := range []string{"add", "remove", "replace"} { + if i == j { + return BgpSetCommunityOptionType(vv) + } + } + return BgpSetCommunityOptionType("") +} + func (v BgpSetCommunityOptionType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid BgpSetCommunityOptionType: %s", v) @@ -283,6 +355,15 @@ func (v BmpRouteMonitoringPolicyType) ToInt() int { return -1 } +func (v BmpRouteMonitoringPolicyType) FromInt(i int) BmpRouteMonitoringPolicyType { + for j, vv := range []string{"pre-policy", "post-policy", "both"} { + if i == j { + return BmpRouteMonitoringPolicyType(vv) + } + } + return BmpRouteMonitoringPolicyType("") +} + func (v BmpRouteMonitoringPolicyType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid BmpRouteMonitoringPolicyType: %s", v) @@ -309,6 +390,15 @@ func (v RpkiValidationResultType) ToInt() int { return -1 } +func (v RpkiValidationResultType) FromInt(i int) RpkiValidationResultType { + for j, vv := range []string{"none", "not-found", "valid", "invalid"} { + if i == j { + return RpkiValidationResultType(vv) + } + } + return RpkiValidationResultType("") +} + func (v RpkiValidationResultType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid RpkiValidationResultType: %s", v) @@ -334,6 +424,15 @@ func (v BgpOriginAttrType) ToInt() int { return -1 } +func (v BgpOriginAttrType) FromInt(i int) BgpOriginAttrType { + for j, vv := range []string{"igp", "egp", "incomplete"} { + if i == j { + return BgpOriginAttrType(vv) + } + } + return BgpOriginAttrType("") +} + func (v BgpOriginAttrType) Validate() error { if v.ToInt() < 0 { return fmt.Errorf("invalid BgpOriginAttrType: %s", v) |