diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-12 10:12:12 +0000 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-14 02:15:47 +0000 |
commit | 1e22e529c92fe7b2e1576ceea96d827f16a76654 (patch) | |
tree | 587c27db5caad26185ff6e0c0aff126b21fe1b2d /config | |
parent | c4ced97e76f12d5c37721c107e61147edb4254d7 (diff) |
config/api: create admin-state type
align with session-state
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r-- | config/bgp_configs.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go index 64971461..300d9058 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -698,6 +698,42 @@ func (v SessionState) Validate() error { return nil } +// typedef for identity bgp:admin-state +type AdminState string + +const ( + ADMIN_STATE_UP AdminState = "up" + ADMIN_STATE_DOWN AdminState = "down" + ADMIN_STATE_PFX_CT AdminState = "pfx_ct" +) + +var AdminStateToIntMap = map[AdminState]int{ + ADMIN_STATE_UP: 0, + ADMIN_STATE_DOWN: 1, + ADMIN_STATE_PFX_CT: 2, +} + +func (v AdminState) ToInt() int { + i, ok := AdminStateToIntMap[v] + if !ok { + return -1 + } + return i +} + +var IntToAdminStateMap = map[int]AdminState{ + 0: ADMIN_STATE_UP, + 1: ADMIN_STATE_DOWN, + 2: ADMIN_STATE_PFX_CT, +} + +func (v AdminState) Validate() error { + if _, ok := AdminStateToIntMap[v]; !ok { + return fmt.Errorf("invalid AdminState: %s", v) + } + return nil +} + // typedef for identity bgp:mode type Mode string @@ -2216,7 +2252,7 @@ type NeighborState struct { //gobgp:admin-down's original type is boolean AdminDown bool `mapstructure:"admin-down" json:"admin-down,omitempty"` // original -> gobgp:admin-state - AdminState string `mapstructure:"admin-state" json:"admin-state,omitempty"` + AdminState AdminState `mapstructure:"admin-state" json:"admin-state,omitempty"` // original -> gobgp:established-count EstablishedCount uint32 `mapstructure:"established-count" json:"established-count,omitempty"` // original -> gobgp:flops |