Skip to content

Commit

Permalink
Add New Go Union Generation under -generate_simple_unions (#451)
Browse files Browse the repository at this point in the history
* Add New Go Union Generation under -generate_simple_unions
  • Loading branch information
wenovus authored Sep 29, 2020
1 parent fb0992c commit 95c14e8
Show file tree
Hide file tree
Showing 59 changed files with 283,903 additions and 77,491 deletions.
10 changes: 2 additions & 8 deletions demo/bgp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,9 @@ func CreateDemoBGPInstance() (*oc.Bgp, error) {
},
}

// Set the peer as a route reflector client using the To_Bgp_Neighbor_RouteReflector_RouteReflectorClusterId_Union
// helper function.
cid, err := (*oc.Bgp_Neighbor_RouteReflector)(nil).To_Bgp_Neighbor_RouteReflector_RouteReflectorClusterId_Union("10.0.1.2")
if err != nil {
return nil, err
}

// Set the peer as a route reflector client using the String union helper typedef.
bgp.Neighbor["192.0.2.1"].RouteReflector = &oc.Bgp_Neighbor_RouteReflector{
RouteReflectorClusterId: cid,
RouteReflectorClusterId: oc.UnionString("10.0.1.2"),
}

return bgp, nil
Expand Down
2 changes: 1 addition & 1 deletion demo/device/devicedemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func CreateDemoDeviceInstance() (*oc.Device, error) {
if err != nil {
return nil, err
}
c.Type = &oc.Component_Type_Union_E_OpenconfigPlatformTypes_OPENCONFIG_SOFTWARE_COMPONENT{oc.OpenconfigPlatformTypes_OPENCONFIG_SOFTWARE_COMPONENT_OPERATING_SYSTEM}
c.Type = oc.OpenconfigPlatformTypes_OPENCONFIG_SOFTWARE_COMPONENT_OPERATING_SYSTEM

// Create a second device instance, and populate the OS component under
// it. This code demonstrates how ygot.MergeStructs can be used to combine
Expand Down
6 changes: 6 additions & 0 deletions demo/getting_started/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func TestGenerateCode(t *testing.T) {
}{{
name: "openconfig interfaces",
inConfig: &ygen.GeneratorConfig{
GoOptions: ygen.GoOpts{
GenerateSimpleUnions: true,
},
ParseOptions: ygen.ParseOpts{
ExcludeModules: []string{"ietf-interfaces"},
},
Expand All @@ -44,6 +47,9 @@ func TestGenerateCode(t *testing.T) {
}, {
name: "openconfig interfaces with no compression",
inConfig: &ygen.GeneratorConfig{
GoOptions: ygen.GoOpts{
GenerateSimpleUnions: true,
},
ParseOptions: ygen.ParseOpts{
ExcludeModules: []string{"ietf-interfaces"},
},
Expand Down
18 changes: 7 additions & 11 deletions demo/gnmi_telemetry/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func CreateAFTInstance() (*oc.Device, error) {
// types for the interface that implements the union within NewLabelEntry.
// Since these types have a single fied, then we can use the anonymous
// initialiser.
if _, err := ni.Afts.NewLabelEntry(&oc.NetworkInstance_Afts_LabelEntry_Label_Union_Uint32{128}); err != nil {
if _, err := ni.Afts.NewLabelEntry(oc.UnionUint32(128)); err != nil {
return nil, err
}

Expand All @@ -102,17 +102,13 @@ func CreateAFTInstance() (*oc.Device, error) {
}
nh.IpAddress = ygot.String("192.0.2.1")

// Each union has a method that is named To_X where the X is the union type, associated
// with the struct that the union is within. This attempts to return the right type
// based on the input interface.
expNull, err := nh.To_NetworkInstance_Afts_NextHop_PushedMplsLabelStack_Union(oc.OpenconfigMplsTypes_MplsLabel_Enum_IPV4_EXPLICIT_NULL)
if err != nil {
return nil, fmt.Errorf("error converting explicit null to union, got: %v", err)
}
// Each union is satisfied by a subset of union typedefs that are
// subtypes of the union. For enumerations and identities, the values
// themselves satisfy the union interface since it's not a primitive type.
nh.PushedMplsLabelStack = []oc.NetworkInstance_Afts_NextHop_PushedMplsLabelStack_Union{
&oc.NetworkInstance_Afts_NextHop_PushedMplsLabelStack_Union_Uint32{42},
&oc.NetworkInstance_Afts_NextHop_PushedMplsLabelStack_Union_Uint32{84},
expNull,
oc.UnionUint32(42),
oc.UnionUint32(84),
oc.OpenconfigMplsTypes_MplsLabel_Enum_IPV4_EXPLICIT_NULL,
}

return d, nil
Expand Down
72,143 changes: 35,789 additions & 36,354 deletions exampleoc/oc.go

Large diffs are not rendered by default.

192 changes: 192 additions & 0 deletions exampleoc/ocpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -157875,6 +157875,198 @@ func (n *RoutingPolicy_PolicyDefinition_Statement_ActionsPathAny) PolicyResult()
}
}

// SetTag returns from RoutingPolicy_PolicyDefinition_Statement_ActionsPath the path struct for its child "set-tag".
func (n *RoutingPolicy_PolicyDefinition_Statement_ActionsPath) SetTag() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath{
NodePath: ygot.NewNodePath(
[]string{"set-tag"},
map[string]interface{}{},
n,
),
}
}

// SetTag returns from RoutingPolicy_PolicyDefinition_Statement_ActionsPathAny the path struct for its child "set-tag".
func (n *RoutingPolicy_PolicyDefinition_Statement_ActionsPathAny) SetTag() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny{
NodePath: ygot.NewNodePath(
[]string{"set-tag"},
map[string]interface{}{},
n,
),
}
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny represents the wildcard version of the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/config/mode YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePath struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePathAny represents the wildcard version of the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/config/mode YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePathAny struct {
*ygot.NodePath
}

// Inline returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath the path struct for its child "inline".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath) Inline() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePath {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePath{
NodePath: ygot.NewNodePath(
[]string{"inline"},
map[string]interface{}{},
n,
),
}
}

// Inline returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny the path struct for its child "inline".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny) Inline() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePathAny {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePathAny{
NodePath: ygot.NewNodePath(
[]string{"inline"},
map[string]interface{}{},
n,
),
}
}

// Mode returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath the path struct for its child "mode".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath) Mode() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePath {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePath{
NodePath: ygot.NewNodePath(
[]string{"config", "mode"},
map[string]interface{}{},
n,
),
}
}

// Mode returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny the path struct for its child "mode".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny) Mode() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePathAny {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ModePathAny{
NodePath: ygot.NewNodePath(
[]string{"config", "mode"},
map[string]interface{}{},
n,
),
}
}

// Reference returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath the path struct for its child "reference".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPath) Reference() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePath {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePath{
NodePath: ygot.NewNodePath(
[]string{"reference"},
map[string]interface{}{},
n,
),
}
}

// Reference returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny the path struct for its child "reference".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTagPathAny) Reference() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePathAny {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePathAny{
NodePath: ygot.NewNodePath(
[]string{"reference"},
map[string]interface{}{},
n,
),
}
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/inline YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePath struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePathAny represents the wildcard version of the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/inline YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePathAny struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/inline/config/tag YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPath struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPathAny represents the wildcard version of the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/inline/config/tag YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPathAny struct {
*ygot.NodePath
}

// Tag returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePath the path struct for its child "tag".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePath) Tag() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPath {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPath{
NodePath: ygot.NewNodePath(
[]string{"config", "tag"},
map[string]interface{}{},
n,
),
}
}

// Tag returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePathAny the path struct for its child "tag".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_InlinePathAny) Tag() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPathAny {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Inline_TagPathAny{
NodePath: ygot.NewNodePath(
[]string{"config", "tag"},
map[string]interface{}{},
n,
),
}
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/reference YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePath struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePathAny represents the wildcard version of the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/reference YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePathAny struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/reference/config/tag-set YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPath struct {
*ygot.NodePath
}

// RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPathAny represents the wildcard version of the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/actions/set-tag/reference/config/tag-set YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPathAny struct {
*ygot.NodePath
}

// TagSet returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePath the path struct for its child "tag-set".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePath) TagSet() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPath {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPath{
NodePath: ygot.NewNodePath(
[]string{"config", "tag-set"},
map[string]interface{}{},
n,
),
}
}

// TagSet returns from RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePathAny the path struct for its child "tag-set".
func (n *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_ReferencePathAny) TagSet() *RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPathAny {
return &RoutingPolicy_PolicyDefinition_Statement_Actions_SetTag_Reference_TagSetPathAny{
NodePath: ygot.NewNodePath(
[]string{"config", "tag-set"},
map[string]interface{}{},
n,
),
}
}

// RoutingPolicy_PolicyDefinition_Statement_ConditionsPath represents the /openconfig-routing-policy/routing-policy/policy-definitions/policy-definition/statements/statement/conditions YANG schema element.
type RoutingPolicy_PolicyDefinition_Statement_ConditionsPath struct {
*ygot.NodePath
Expand Down
Loading

0 comments on commit 95c14e8

Please sign in to comment.