Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions dataplane/standalone/apigen/apigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
cc "modernc.org/cc/v4"
)

func parse(header string, includePaths ...string) (*cc.AST, error) {
func parse(headers []string, includePaths ...string) (*cc.AST, error) {
cfg, err := cc.NewConfig(runtime.GOOS, runtime.GOARCH)
if err != nil {
return nil, err
Expand All @@ -38,7 +38,10 @@ func parse(header string, includePaths ...string) (*cc.AST, error) {
cfg.SysIncludePaths = append(cfg.SysIncludePaths, p)
}

sources := []cc.Source{{Name: "<predefined>", Value: cfg.Predefined}, {Name: "<builtin>", Value: cc.Builtin}, {Name: header}}
sources := []cc.Source{{Name: "<predefined>", Value: cfg.Predefined}, {Name: "<builtin>", Value: cc.Builtin}}
for _, hdr := range headers {
sources = append(sources, cc.Source{Name: hdr})
}
ast, err := cc.Translate(cfg, sources)
if err != nil {
return nil, err
Expand All @@ -53,7 +56,11 @@ const (
)

func generate() error {
headerFile, err := filepath.Abs(filepath.Join(saiPath, "inc/sai.h"))
saiHeaderFile, err := filepath.Abs(filepath.Join(saiPath, "inc/sai.h"))
if err != nil {
return err
}
expHeaderFile, err := filepath.Abs(filepath.Join(saiPath, "experimental/saiextensions.h"))
if err != nil {
return err
}
Expand All @@ -65,7 +72,7 @@ func generate() error {
if err != nil {
return err
}
ast, err := parse(headerFile, incDir, experiDir)
ast, err := parse([]string{saiHeaderFile, expHeaderFile}, incDir, experiDir)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion dataplane/standalone/apigen/ccgen/ccgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func protoFieldGetter(saiType, protoField, varName string, info *docparser.SAIIn
return smt, nil
case variableSizedArray:
smt.CopyConvertFunc = "copy_list"
smt.CopyConvertFuncArgs = fmt.Sprintf(", %s.count", smt.Var)
smt.CopyConvertFuncArgs = fmt.Sprintf(", &%s.count", smt.Var)
smt.Var += ".list"
return smt, nil
}
Expand Down Expand Up @@ -376,6 +376,7 @@ var (

extern "C" {
#include "inc/sai.h"
#include "experimental/saiextensions.h"
}

extern const {{ .APIType }} l_{{ .APIName }};
Expand Down
30 changes: 28 additions & 2 deletions dataplane/standalone/apigen/protogen/protogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ func populateTmplDataFromFunc(apis map[string]*protoAPITmplData, docInfo *docpar
req.Fields = append(req.Fields, idField)
requestIdx++
}
for _, v := range docInfo.Enums["sai_object_type_t"] {
if v == fmt.Sprintf("SAI_OBJECT_TYPE_%s", meta.TypeName) {
req.Option = fmt.Sprintf("option (sai_type) = OBJECT_TYPE_%s", meta.TypeName)
}
}
if req.Option == "" {
req.Option = "option (sai_type) = OBJECT_TYPE_UNSPECIFIED"
}

attrs, err := createAttrs(requestIdx, meta.TypeName, docInfo, docInfo.Attrs[meta.TypeName].CreateFields)
if err != nil {
Expand Down Expand Up @@ -310,6 +318,9 @@ enum {{ .Name }} {

{{ range .Messages }}
message {{ .Name }} {
{{- if .Option }}
{{ .Option }};
{{- end -}}
{{- range .Fields }}
{{ .ProtoType }} {{ .Name }} = {{ .Index }} {{- if .Option -}} {{ .Option }} {{- end -}};
{{- end }}
Expand All @@ -335,11 +346,25 @@ option go_package = "github.com/openconfig/lemming/dataplane/standalone/proto";
extend google.protobuf.FieldOptions {
optional int32 attr_enum_value = 50000;
}

extend google.protobuf.MessageOptions {
optional ObjectType sai_type = 50001;
}
{{ range .Messages }}
{{ . }}
{{ end -}}
{{ end }}
message ObjectTypeQueryRequest {
uint64 object = 1;
}

message ObjectTypeQueryResponse {
ObjectType type = 1;
}

{{- range .Enums }}
service Entrypoint {
rpc ObjectTypeQuery(ObjectTypeQueryRequest) returns (ObjectTypeQueryResponse) {}
}
{{ range .Enums }}
enum {{ .Name }} {
{{- range .Values }}
{{ .Name }} = {{ .Index }};
Expand Down Expand Up @@ -384,6 +409,7 @@ type protoEnumValues struct {

type protoTmplMessage struct {
Name string
Option string
Fields []protoTmplField
}

Expand Down
18 changes: 18 additions & 0 deletions dataplane/standalone/apigen/protogen/protogen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ extend google.protobuf.FieldOptions {
optional int32 attr_enum_value = 50000;
}

extend google.protobuf.MessageOptions {
optional ObjectType sai_type = 50001;
}

message AclActionData {
bool enable = 1;
oneof parameter {
Expand Down Expand Up @@ -266,6 +270,18 @@ message Uint32Range {
uint64 min = 1;
uint64 max = 2;
}

message ObjectTypeQueryRequest {
uint64 object = 1;
}

message ObjectTypeQueryResponse {
ObjectType type = 1;
}

service Entrypoint {
rpc ObjectTypeQuery(ObjectTypeQueryRequest) returns (ObjectTypeQueryResponse) {}
}
`
)

Expand Down Expand Up @@ -416,6 +432,7 @@ enum FooAttr {
}

message CreateFooRequest {
option (sai_type) = OBJECT_TYPE_UNSPECIFIED;
optional uint32 sample_uint = 1;
}

Expand Down Expand Up @@ -526,6 +543,7 @@ enum FooAttr {
}

message CreateFooRequest {
option (sai_type) = OBJECT_TYPE_UNSPECIFIED;
uint64 switch = 1;
optional uint32 sample_uint = 2;
}
Expand Down
62 changes: 61 additions & 1 deletion dataplane/standalone/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ proto_library(
srcs = [
"acl.proto",
"bfd.proto",
"bmtor.proto",
"bridge.proto",
"buffer.proto",
"common.proto",
Expand Down Expand Up @@ -65,7 +66,7 @@ go_proto_library(
name = "sai_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/openconfig/lemming/dataplane/standalone/proto",
proto = ":sai_proto",
proto = ":proto_proto",
visibility = ["//visibility:public"],
)

Expand All @@ -89,3 +90,62 @@ cc_grpc_library(
visibility = ["//visibility:public"],
deps = [":sai_cc_proto"],
)

proto_library(
name = "proto_proto",
srcs = [
"acl.proto",
"bfd.proto",
"bmtor.proto",
"bridge.proto",
"buffer.proto",
"common.proto",
"counter.proto",
"debug_counter.proto",
"dtel.proto",
"fdb.proto",
"hash.proto",
"hostif.proto",
"ipmc.proto",
"ipmc_group.proto",
"ipsec.proto",
"isolation_group.proto",
"l2mc.proto",
"l2mc_group.proto",
"lag.proto",
"macsec.proto",
"mcast_fdb.proto",
"mirror.proto",
"mpls.proto",
"my_mac.proto",
"nat.proto",
"neighbor.proto",
"next_hop.proto",
"next_hop_group.proto",
"policer.proto",
"port.proto",
"qos_map.proto",
"queue.proto",
"route.proto",
"router_interface.proto",
"rpf_group.proto",
"samplepacket.proto",
"scheduler.proto",
"scheduler_group.proto",
"srv6.proto",
"stp.proto",
"switch.proto",
"system_port.proto",
"tam.proto",
"tunnel.proto",
"udf.proto",
"virtual_router.proto",
"vlan.proto",
"wred.proto",
],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
Loading