Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions/checkout-4
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus authored Sep 28, 2023
2 parents 2d9c4c8 + 23c9aac commit 5dabefb
Show file tree
Hide file tree
Showing 16 changed files with 145,298 additions and 130,968 deletions.
93,551 changes: 49,129 additions & 44,422 deletions exampleoc/oc.go

Large diffs are not rendered by default.

4,895 changes: 4,307 additions & 588 deletions exampleoc/ocpath.go

Large diffs are not rendered by default.

92,494 changes: 48,488 additions & 44,006 deletions exampleoc/opstateoc/oc.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exampleoc/opstateoc/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go run ../../generator/generator.go -path=public,deps -output_file=oc.go \
public/release/models/optical-transport/openconfig-terminal-device.yang \
public/release/models/optical-transport/openconfig-transport-line-protection.yang \
public/release/models/platform/openconfig-platform.yang \
public/release/models/bgp/openconfig-bgp-policy.yang \
public/release/models/policy/openconfig-routing-policy.yang \
public/release/models/lacp/openconfig-lacp.yang \
public/release/models/system/openconfig-system.yang \
Expand Down
1 change: 1 addition & 0 deletions exampleoc/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go run ../generator/generator.go -path=public,deps -output_file=oc.go \
public/release/models/optical-transport/openconfig-terminal-device.yang \
public/release/models/optical-transport/openconfig-transport-line-protection.yang \
public/release/models/platform/openconfig-platform.yang \
public/release/models/bgp/openconfig-bgp-policy.yang \
public/release/models/policy/openconfig-routing-policy.yang \
public/release/models/lacp/openconfig-lacp.yang \
public/release/models/system/openconfig-system.yang \
Expand Down
5 changes: 5 additions & 0 deletions exampleoc/wrapperunionoc/oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ It should not be used within your application, as it WILL change,
without warning. Rather, you should generate structs directly from
OpenConfig models using the ygot package.

NOTE WELL: This is an example code file that is distributed with ygot.
It should not be used within your application, as it WILL change,
without warning. Rather, you should generate structs directly from
OpenConfig models using the ygot package.

This package was generated by github.com/openconfig/ygot
using the following YANG input files:
- public/release/models/network-instance/openconfig-network-instance.yang
Expand Down
9 changes: 6 additions & 3 deletions gogen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"sort"
"strings"

"github.com/openconfig/ygot/internal/igenutil"
"github.com/openconfig/ygot/util"
Expand Down Expand Up @@ -274,8 +273,7 @@ func (cg *CodeGenerator) Generate(yangFiles, includePaths []string) (*GeneratedC
for _, fn := range dir.OrderedFieldNames() {
field := dir.Fields[fn]

// Strip the module name from the path.
schemaPath := util.SlicePathToString(append([]string{""}, strings.Split(field.YANGDetails.Path, "/")[2:]...))
schemaPath := field.YANGDetails.SchemaPath
switch {
case field.LangType == nil:
// This is a directory, so we continue.
Expand Down Expand Up @@ -304,6 +302,11 @@ func (cg *CodeGenerator) Generate(yangFiles, includePaths []string) (*GeneratedC
return field.LangType.UnionTypes[enumTypeMap[schemaPath][i]].Index < field.LangType.UnionTypes[enumTypeMap[schemaPath][j]].Index
})
}
if v, ok := enumTypeMap[schemaPath]; ok {
if shadowPath := field.YANGDetails.ShadowSchemaPath; shadowPath != "" {
enumTypeMap[shadowPath] = v
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,8 @@ func initΛEnumTypes(){
"/parent/child/config/three": []reflect.Type{
reflect.TypeOf((E_Child_Three)(0)),
},
"/parent/child/state/three": []reflect.Type{
reflect.TypeOf((E_Child_Three)(0)),
},
}
}
144 changes: 144 additions & 0 deletions protomap/integration_tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/openconfig/gnmi/value"
"github.com/openconfig/ygot/protomap"
"github.com/openconfig/ygot/protomap/integration_tests/testdata/gribi_aft"
"github.com/openconfig/ygot/testutil"
Expand All @@ -14,6 +15,7 @@ import (
"google.golang.org/protobuf/testing/protocmp"

gpb "github.com/openconfig/gnmi/proto/gnmi"
wpb "github.com/openconfig/ygot/proto/ywrapper"
)

func mustPath(p string) *gpb.Path {
Expand Down Expand Up @@ -89,6 +91,28 @@ func TestGRIBIAFT(t *testing.T) {
mustPath("afts/next-hops/next-hop[index=1]/index"): uint64(1),
mustPath("afts/next-hops/next-hop[index=1]/state/index"): uint64(1),
},
}, {
desc: "NHG entry",
inProto: &gribi_aft.Afts{
NextHopGroup: []*gribi_aft.Afts_NextHopGroupKey{{
Id: 1,
NextHopGroup: &gribi_aft.Afts_NextHopGroup{
NextHop: []*gribi_aft.Afts_NextHopGroup_NextHopKey{{
Index: 1,
NextHop: &gribi_aft.Afts_NextHopGroup_NextHop{
Weight: &wpb.UintValue{Value: 1},
},
}},
},
}},
},
wantPaths: map[*gpb.Path]interface{}{
mustPath("afts/next-hop-groups/next-hop-group[id=1]/id"): uint64(1),
mustPath("afts/next-hop-groups/next-hop-group[id=1]/state/id"): uint64(1),
mustPath("afts/next-hop-groups/next-hop-group[id=1]/next-hops/next-hop[index=1]/index"): uint64(1),
mustPath("afts/next-hop-groups/next-hop-group[id=1]/next-hops/next-hop[index=1]/state/index"): uint64(1),
mustPath("afts/next-hop-groups/next-hop-group[id=1]/next-hops/next-hop[index=1]/state/weight"): uint64(1),
},
}}

for _, tt := range tests {
Expand All @@ -103,3 +127,123 @@ func TestGRIBIAFT(t *testing.T) {
})
}
}

func mustValue(t *testing.T, v any) *gpb.TypedValue {
tv, err := value.FromScalar(v)
if err != nil {
t.Fatalf("cannot create gNMI TypedValue from %v %T, err: %v", v, v, err)
}
return tv
}

func TestGRIBIAFTToStruct(t *testing.T) {
tests := []struct {
desc string
inPaths map[*gpb.Path]interface{}
inProto proto.Message
inPrefix *gpb.Path
wantProto proto.Message
wantErr bool
}{{
desc: "ipv4 prefix",
inPaths: map[*gpb.Path]interface{}{
mustPath("state/entry-metadata"): mustValue(t, []byte{1, 2, 3}),
},
inProto: &gribi_aft.Afts_Ipv4Entry{},
inPrefix: mustPath("afts/ipv4-unicast/ipv4-entry"),
wantProto: &gribi_aft.Afts_Ipv4Entry{
EntryMetadata: &wpb.BytesValue{Value: []byte{1, 2, 3}},
},
}, {
desc: "map next-hop-group",
inPaths: map[*gpb.Path]interface{}{
mustPath("next-hops/next-hop[index=1]/index"): mustValue(t, uint64(1)),
mustPath("next-hops/next-hop[index=1]/state/index"): mustValue(t, uint64(1)),
mustPath("next-hops/next-hop[index=1]/state/weight"): mustValue(t, uint64(1)),
},
inProto: &gribi_aft.Afts_NextHopGroup{},
inPrefix: &gpb.Path{
Elem: []*gpb.PathElem{{
Name: "afts",
}, {
Name: "next-hop-groups",
}, {
Name: "next-hop-group",
}},
},
wantProto: &gribi_aft.Afts_NextHopGroup{
NextHop: []*gribi_aft.Afts_NextHopGroup_NextHopKey{{
Index: 1,
NextHop: &gribi_aft.Afts_NextHopGroup_NextHop{
Weight: &wpb.UintValue{Value: 1},
},
}},
},
}, {
desc: "multiple NHGs",
inPaths: map[*gpb.Path]interface{}{
mustPath("next-hops/next-hop[index=1]/index"): mustValue(t, uint64(1)),
mustPath("next-hops/next-hop[index=1]/state/index"): mustValue(t, uint64(1)),
mustPath("next-hops/next-hop[index=1]/state/weight"): mustValue(t, uint64(1)),
mustPath("next-hops/next-hop[index=2]/index"): mustValue(t, uint64(2)),
mustPath("next-hops/next-hop[index=2]/state/index"): mustValue(t, uint64(2)),
mustPath("next-hops/next-hop[index=2]/state/weight"): mustValue(t, uint64(2)),
},
inProto: &gribi_aft.Afts_NextHopGroup{},
inPrefix: &gpb.Path{
Elem: []*gpb.PathElem{{
Name: "afts",
}, {
Name: "next-hop-groups",
}, {
Name: "next-hop-group",
}},
},
wantProto: &gribi_aft.Afts_NextHopGroup{
NextHop: []*gribi_aft.Afts_NextHopGroup_NextHopKey{{
Index: 1,
NextHop: &gribi_aft.Afts_NextHopGroup_NextHop{
Weight: &wpb.UintValue{Value: 1},
},
}, {
Index: 2,
NextHop: &gribi_aft.Afts_NextHopGroup_NextHop{
Weight: &wpb.UintValue{Value: 2},
},
}},
},
}, {
desc: "embedded field in next-hop",
inPaths: map[*gpb.Path]interface{}{
mustPath("ip-in-ip/state/src-ip"): mustValue(t, "1.1.1.1"),
},
inProto: &gribi_aft.Afts_NextHop{},
inPrefix: mustPath("afts/next-hops/next-hop"),
wantProto: &gribi_aft.Afts_NextHop{
IpInIp: &gribi_aft.Afts_NextHop_IpInIp{
SrcIp: &wpb.StringValue{Value: "1.1.1.1"},
},
},
}}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
if err := protomap.ProtoFromPaths(tt.inProto, tt.inPaths,
protomap.ProtobufMessagePrefix(tt.inPrefix),
protomap.ValuePathPrefix(tt.inPrefix),
); err != nil {
if !tt.wantErr {
t.Fatalf("cannot unmarshal paths, err: %v, wantErr? %v", err, tt.wantErr)
}
return
}

if diff := cmp.Diff(tt.inProto, tt.wantProto,
protocmp.Transform(),
protocmp.SortRepeatedFields(&gribi_aft.Afts_NextHopGroup{}, "next_hop"),
); diff != "" {
t.Fatalf("did not get expected protobuf, diff(-got,+want):\n%s", diff)
}
})
}
}
Loading

0 comments on commit 5dabefb

Please sign in to comment.