Skip to content

Commit 5a6d70e

Browse files
DanG100robshakir
andauthored
Handle enums in protomap (#1012)
Co-authored-by: Rob Shakir <[email protected]>
1 parent 9e8f11b commit 5a6d70e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

protomap/integration_tests/integration_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/google/go-cmp/cmp/cmpopts"
99
"github.com/openconfig/gnmi/value"
10+
"github.com/openconfig/gribi/v1/proto/gribi_aft/enums"
1011
"github.com/openconfig/ygot/protomap"
1112
"github.com/openconfig/ygot/testutil"
1213
"github.com/openconfig/ygot/ygot"
@@ -91,6 +92,23 @@ func TestGRIBIAFT(t *testing.T) {
9192
mustPath("afts/next-hops/next-hop[index=1]/index"): uint64(1),
9293
mustPath("afts/next-hops/next-hop[index=1]/state/index"): uint64(1),
9394
},
95+
}, {
96+
desc: "NH entry with enum",
97+
inProto: &aftpb.Afts{
98+
NextHop: []*aftpb.Afts_NextHopKey{{
99+
Index: 1,
100+
NextHop: &aftpb.Afts_NextHop{
101+
IpAddress: &wpb.StringValue{Value: "127.0.0.1"},
102+
EncapsulateHeader: enums.OpenconfigAftTypesEncapsulationHeaderType_OPENCONFIGAFTTYPESENCAPSULATIONHEADERTYPE_IPV4,
103+
},
104+
}},
105+
},
106+
wantPaths: map[*gpb.Path]interface{}{
107+
mustPath("afts/next-hops/next-hop[index=1]/state/ip-address"): "127.0.0.1",
108+
mustPath("afts/next-hops/next-hop[index=1]/index"): uint64(1),
109+
mustPath("afts/next-hops/next-hop[index=1]/state/index"): uint64(1),
110+
mustPath("afts/next-hops/next-hop[index=1]/state/encapsulate-header"): "IPV4",
111+
},
94112
}, {
95113
desc: "NHG entry",
96114
inProto: &aftpb.Afts{

protomap/proto.go

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func parseField(fd protoreflect.FieldDescriptor, v protoreflect.Value, vals map[
114114
}
115115
}
116116

117+
// Handle enum values by using the enum value option extension to convert value to string.
118+
if fd.Kind() == protoreflect.EnumKind {
119+
po := fd.Enum().Values().ByNumber(val.(protoreflect.EnumNumber)).Options().(*descriptorpb.EnumValueOptions)
120+
ex := proto.GetExtension(po, yextpb.E_YangName).(string)
121+
val = ex
122+
}
123+
117124
// Handle cases where there is >1 path specified for a field based on
118125
// path compression.
119126
for _, path := range annotatedPath {

0 commit comments

Comments
 (0)