mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
config: add go type of embeded enums defined in openconfig
these types are embeded enums of openconfig and were left uint32 Signed-off-by: ISHIDA Wataru <[email protected]>
This commit is contained in:
committed by
FUJITA Tomonori
parent
4ad751b4f0
commit
cca91da0df
+107
-6
@@ -298,6 +298,39 @@ func (v MatchSetOptionsType) DefaultAsNeeded() MatchSetOptionsType {
|
||||
// typedef for typedef ptypes:tag-type
|
||||
type TagType string
|
||||
|
||||
// typedef for typedef rpol:route-type
|
||||
type RouteType string
|
||||
|
||||
const (
|
||||
ROUTE_TYPE_INTERNAL RouteType = "internal"
|
||||
ROUTE_TYPE_EXTERNAL RouteType = "external"
|
||||
)
|
||||
|
||||
func (v RouteType) ToInt() int {
|
||||
for i, vv := range []string{"internal", "external"} {
|
||||
if string(v) == vv {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (v RouteType) FromInt(i int) RouteType {
|
||||
for j, vv := range []string{"internal", "external"} {
|
||||
if i == j {
|
||||
return RouteType(vv)
|
||||
}
|
||||
}
|
||||
return RouteType("")
|
||||
}
|
||||
|
||||
func (v RouteType) Validate() error {
|
||||
if v.ToInt() < 0 {
|
||||
return fmt.Errorf("invalid RouteType: %s", v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// typedef for typedef rpol:default-policy-type
|
||||
type DefaultPolicyType string
|
||||
|
||||
@@ -331,6 +364,77 @@ func (v DefaultPolicyType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// typedef for typedef bgp:session-state
|
||||
type SessionState string
|
||||
|
||||
const (
|
||||
SESSION_STATE_IDLE SessionState = "idle"
|
||||
SESSION_STATE_CONNECT SessionState = "connect"
|
||||
SESSION_STATE_ACTIVE SessionState = "active"
|
||||
SESSION_STATE_OPENSENT SessionState = "opensent"
|
||||
SESSION_STATE_OPENCONFIRM SessionState = "openconfirm"
|
||||
SESSION_STATE_ESTABLISHED SessionState = "established"
|
||||
)
|
||||
|
||||
func (v SessionState) ToInt() int {
|
||||
for i, vv := range []string{"idle", "connect", "active", "opensent", "openconfirm", "established"} {
|
||||
if string(v) == vv {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (v SessionState) FromInt(i int) SessionState {
|
||||
for j, vv := range []string{"idle", "connect", "active", "opensent", "openconfirm", "established"} {
|
||||
if i == j {
|
||||
return SessionState(vv)
|
||||
}
|
||||
}
|
||||
return SessionState("")
|
||||
}
|
||||
|
||||
func (v SessionState) Validate() error {
|
||||
if v.ToInt() < 0 {
|
||||
return fmt.Errorf("invalid SessionState: %s", v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// typedef for typedef bgp:mode
|
||||
type Mode string
|
||||
|
||||
const (
|
||||
MODE_HELPER_ONLY Mode = "helper-only"
|
||||
MODE_BILATERAL Mode = "bilateral"
|
||||
MODE_REMOTE_HELPER Mode = "remote-helper"
|
||||
)
|
||||
|
||||
func (v Mode) ToInt() int {
|
||||
for i, vv := range []string{"helper-only", "bilateral", "remote-helper"} {
|
||||
if string(v) == vv {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (v Mode) FromInt(i int) Mode {
|
||||
for j, vv := range []string{"helper-only", "bilateral", "remote-helper"} {
|
||||
if i == j {
|
||||
return Mode(vv)
|
||||
}
|
||||
}
|
||||
return Mode("")
|
||||
}
|
||||
|
||||
func (v Mode) Validate() error {
|
||||
if v.ToInt() < 0 {
|
||||
return fmt.Errorf("invalid Mode: %s", v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// typedef for typedef bgp-pol:bgp-next-hop-type
|
||||
type BgpNextHopType string
|
||||
|
||||
@@ -978,8 +1082,7 @@ type NeighborState struct {
|
||||
//bgp:neighbor-address's original type is inet:ip-address
|
||||
NeighborAddress string `mapstructure:"neighbor-address"`
|
||||
// original -> bgp-op:session-state
|
||||
//bgp-op:session-state's original type is enumeration
|
||||
SessionState uint32 `mapstructure:"session-state"`
|
||||
SessionState SessionState `mapstructure:"session-state"`
|
||||
// original -> bgp-op:supported-capabilities
|
||||
// original type is list of identityref
|
||||
SupportedCapabilitiesList []string `mapstructure:"supported-capabilities-list"`
|
||||
@@ -1396,8 +1499,7 @@ type GracefulRestartState struct {
|
||||
//bgp-op:local-restarting's original type is boolean
|
||||
LocalRestarting bool `mapstructure:"local-restarting"`
|
||||
// original -> bgp-op:mode
|
||||
//bgp-op:mode's original type is enumeration
|
||||
Mode uint32 `mapstructure:"mode"`
|
||||
Mode Mode `mapstructure:"mode"`
|
||||
}
|
||||
|
||||
//struct for container bgp:config
|
||||
@@ -1827,8 +1929,7 @@ type BgpConditions struct {
|
||||
// original -> bgp-pol:as-path-length
|
||||
AsPathLength AsPathLength `mapstructure:"as-path-length"`
|
||||
// original -> bgp-pol:route-type
|
||||
//bgp-pol:route-type's original type is enumeration
|
||||
RouteType uint32 `mapstructure:"route-type"`
|
||||
RouteType RouteType `mapstructure:"route-type"`
|
||||
// original -> gobgp:rpki-validation-result
|
||||
RpkiValidationResult RpkiValidationResultType `mapstructure:"rpki-validation-result"`
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager, pol
|
||||
tableId = conf.Config.NeighborAddress
|
||||
}
|
||||
peer.tableId = tableId
|
||||
conf.State.SessionState = uint32(bgp.BGP_FSM_IDLE)
|
||||
conf.State.SessionState = conf.State.SessionState.FromInt(int(bgp.BGP_FSM_IDLE))
|
||||
conf.Timers.State.Downtime = time.Now().Unix()
|
||||
rfs, _ := config.AfiSafis(conf.AfiSafis).ToRfList()
|
||||
peer.adjRibIn = table.NewAdjRib(peer.ID(), rfs)
|
||||
|
||||
+2
-2
@@ -910,8 +910,8 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) []*SenderMsg {
|
||||
switch e.MsgType {
|
||||
case FSM_MSG_STATE_CHANGE:
|
||||
nextState := e.MsgData.(bgp.FSMState)
|
||||
oldState := bgp.FSMState(peer.conf.State.SessionState)
|
||||
peer.conf.State.SessionState = uint32(nextState)
|
||||
oldState := bgp.FSMState(peer.conf.State.SessionState.ToInt())
|
||||
peer.conf.State.SessionState = peer.conf.State.SessionState.FromInt(int(nextState))
|
||||
peer.fsm.StateChange(nextState)
|
||||
|
||||
if oldState == bgp.BGP_FSM_ESTABLISHED {
|
||||
|
||||
@@ -166,6 +166,9 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
|
||||
else:
|
||||
emit_type_name = t.arg
|
||||
|
||||
# case embeded enumeration
|
||||
elif type_name == 'enumeration':
|
||||
emit_type_name = val_name_go
|
||||
|
||||
# case translation required
|
||||
elif is_translation_required(type_obj):
|
||||
@@ -290,6 +293,16 @@ def visit_children(ctx, module, children):
|
||||
|
||||
t = c.search_one('type')
|
||||
|
||||
# define container embeded enums
|
||||
if is_leaf(c) and c.search_one('type').arg == 'enumeration':
|
||||
prefix = module.i_prefix
|
||||
c.path = get_path(c)
|
||||
c.golang_name = convert_to_golang(c.arg)
|
||||
if prefix in ctx.golang_typedef_map:
|
||||
ctx.golang_typedef_map[prefix][c.arg] = c
|
||||
else:
|
||||
ctx.golang_typedef_map[prefix] = {c.arg: c}
|
||||
|
||||
if is_list(c) or is_container(c) or is_choice(c):
|
||||
c.golang_name = convert_to_golang(c.uniq_name)
|
||||
|
||||
@@ -542,7 +555,6 @@ def is_translation_required(t):
|
||||
|
||||
_type_translation_map = {
|
||||
'union': 'string',
|
||||
'enumeration': 'uint32',
|
||||
'decimal64': 'float64',
|
||||
'boolean': 'bool',
|
||||
'empty': 'bool',
|
||||
|
||||
Reference in New Issue
Block a user