Skip to content

Commit

Permalink
Support proto generation get stats API (#310)
Browse files Browse the repository at this point in the history
* Support get stats API

* lint

* lint
  • Loading branch information
DanG100 authored Oct 23, 2023
1 parent 72d09c6 commit 82231ce
Show file tree
Hide file tree
Showing 31 changed files with 10,037 additions and 5,461 deletions.
19 changes: 16 additions & 3 deletions dataplane/standalone/apigen/protogen/protogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func generateCommonTypes(docInfo *docparser.SAIInfo) (string, error) {
return builder.String(), nil
}

const repeatedType = "repeated "

// populateTmplDataFromFunc populatsd the protobuf template struct from a SAI function call.
func populateTmplDataFromFunc(apis map[string]*protoAPITmplData, docInfo *docparser.SAIInfo, apiName string, meta *saiast.FuncMetadata) error {
if docInfo.Attrs[meta.TypeName] == nil {
Expand Down Expand Up @@ -213,7 +215,7 @@ func populateTmplDataFromFunc(apis map[string]*protoAPITmplData, docInfo *docpar
req.Fields = append(req.Fields, attrs...)
case "get_attribute":
req.Fields = append(req.Fields, idField, protoTmplField{
ProtoType: "repeated " + strcase.UpperCamelCase(meta.TypeName+" attr"),
ProtoType: repeatedType + strcase.UpperCamelCase(meta.TypeName+" attr"),
Index: 2,
Name: "attr_type",
})
Expand Down Expand Up @@ -262,12 +264,23 @@ func populateTmplDataFromFunc(apis map[string]*protoAPITmplData, docInfo *docpar
case "create_bulk":
req.Fields = append(req.Fields, protoTmplField{
Name: "reqs",
ProtoType: "repeated " + strcase.UpperCamelCase("Create "+meta.TypeName+"Request"),
ProtoType: repeatedType + strcase.UpperCamelCase("Create "+meta.TypeName+"Request"),
Index: 1,
})
resp.Fields = append(resp.Fields, protoTmplField{
Name: "resps",
ProtoType: "repeated " + strcase.UpperCamelCase("Create "+meta.TypeName+"Response"),
ProtoType: repeatedType + strcase.UpperCamelCase("Create "+meta.TypeName+"Response"),
Index: 1,
})
case "get_stats":
req.Fields = append(req.Fields, idField, protoTmplField{
Name: "counter_ids",
ProtoType: fmt.Sprintf("repeated %s", strcase.UpperCamelCase(meta.TypeName+" stat")),
Index: 2,
})
resp.Fields = append(resp.Fields, protoTmplField{
Name: "values",
ProtoType: "uint64",
Index: 1,
})
default:
Expand Down
14 changes: 14 additions & 0 deletions dataplane/standalone/apigen/protogen/protogen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,17 @@ service Sample {
}, {
Name: "get_foo_attribute",
Typ: "sai_get_foo_attribute_t",
}, {
Name: "get_foo_stats",
Typ: "sai_get_foo_stats_t",
}},
}},
Funcs: map[string]*saiast.SAIFunc{
"sai_create_foo_t": {Params: []saiast.TypeDecl{{Name: "object_id", Typ: "*sai_object_id_t"}, {Name: "switch_id", Typ: "sai_object_id_t"}}},
"sai_remove_foo_t": {},
"sai_set_foo_attribute_t": {},
"sai_get_foo_attribute_t": {},
"sai_get_foo_stats_t": {},
},
},
inInfo: &docparser.SAIInfo{
Expand Down Expand Up @@ -595,11 +599,21 @@ message GetFooAttributeResponse {
FooAttribute attr = 1;
}
message GetFooStatsRequest {
uint64 oid = 1;
repeated FooStat counter_ids = 2;
}
message GetFooStatsResponse {
uint64 values = 1;
}
service Sample {
rpc CreateFoo (CreateFooRequest) returns (CreateFooResponse) {}
rpc RemoveFoo (RemoveFooRequest) returns (RemoveFooResponse) {}
rpc GetFooAttribute (GetFooAttributeRequest) returns (GetFooAttributeResponse) {}
rpc GetFooStats (GetFooStatsRequest) returns (GetFooStatsResponse) {}
}
`,
},
Expand Down
481 changes: 334 additions & 147 deletions dataplane/standalone/proto/bfd.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions dataplane/standalone/proto/bfd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ message GetBfdSessionAttributeResponse {
BfdSessionAttribute attr = 1;
}

message GetBfdSessionStatsRequest {
uint64 oid = 1;
repeated BfdSessionStat counter_ids = 2;
}

message GetBfdSessionStatsResponse {
uint64 values = 1;
}

service Bfd {
rpc CreateBfdSession(CreateBfdSessionRequest)
returns (CreateBfdSessionResponse) {}
Expand All @@ -140,4 +149,6 @@ service Bfd {
returns (SetBfdSessionAttributeResponse) {}
rpc GetBfdSessionAttribute(GetBfdSessionAttributeRequest)
returns (GetBfdSessionAttributeResponse) {}
rpc GetBfdSessionStats(GetBfdSessionStatsRequest)
returns (GetBfdSessionStatsResponse) {}
}
Loading

0 comments on commit 82231ce

Please sign in to comment.