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
24 changes: 23 additions & 1 deletion dataplane/apigen/ccgen/ccgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

var unsupportedEnum = map[string]struct{}{
"FDB_FLUSH": {},
"HOSTIF_PACKET": {},
}

Expand Down Expand Up @@ -243,6 +242,13 @@ lemming::dataplane::sai::{{ .ReturnType }} msg;
for(uint32_t i = 0; i < attr_count; i++ ) {
{{ template "getattr" .AttrSwitch }}
}
{{- else if eq .Operation "flush" }}
lemming::dataplane::sai::{{ .ProtoRequestType }} msg;
msg.set_switch_(switch_id);
for(uint32_t i = 0; i < attr_count; i++ ) {
{{ .AttrConvertInsert }}
{{ template "setattr" .AttrSwitch }}
}
{{- end }}
return msg;
}
Expand Down Expand Up @@ -417,6 +423,22 @@ return msg;
}
{{ end }}
return SAI_STATUS_SUCCESS;
{{- else if eq .Operation "flush" }}
lemming::dataplane::sai::{{ .ProtoRequestType }} req = {{.ConvertFunc}}(switch_id, {{.Vars}});
lemming::dataplane::sai::{{ .ProtoResponseType }} resp;
grpc::ClientContext context;

grpc::Status status = {{ .Client }}->{{ .ProtoRPCName }}(&context, req, &resp);
if (!status.ok()) {
auto it = context.GetServerTrailingMetadata().find("traceparent");
if (it != context.GetServerTrailingMetadata().end()) {
LOG(ERROR) << "Lucius RPC error: Trace ID " << it->second << " msg: " << status.error_message();
} else {
LOG(ERROR) << "Lucius RPC error: " << status.error_message();
}
return SAI_STATUS_FAILURE;
}
return SAI_STATUS_SUCCESS;
{{- else }}
return SAI_STATUS_NOT_IMPLEMENTED;
{{- end }}
Expand Down
5 changes: 5 additions & 0 deletions dataplane/apigen/saiast/saiast.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func (sai *SAIAPI) GetFuncMeta(fn *TypeDecl) *FuncMetadata {
}
}

if meta.Name == "flush_fdb_entries" {
meta.Operation = "flush"
meta.TypeName = "FDB_FLUSH"
}

return meta
}

Expand Down
27 changes: 23 additions & 4 deletions dataplane/apigen/typeinfo/typeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func Data(doc *docparser.SAIInfo, sai *saiast.SAIAPI, protoPackage, protoGoPacka

populateCCInfo(meta, apiName, sai, doc, fn, gFunc)

if gFunc.Operation == getAttrOp {
if gFunc.Operation == getAttrOp || gFunc.Operation == flushOp {
enum := genProtoEnum(doc, apiName, meta)
if enum != nil {
data.APIs[apiName].Enums = append(data.APIs[apiName].Enums, *enum)
Expand All @@ -134,7 +134,7 @@ func Data(doc *docparser.SAIInfo, sai *saiast.SAIAPI, protoPackage, protoGoPacka
data.APIs[apiName].Funcs = append(data.APIs[apiName].Funcs, fns...)
data.APIs[apiName].Types = append(data.APIs[apiName].Types, msgs...)
}
if gFunc.Operation == createOp {
if gFunc.Operation == createOp || gFunc.Operation == flushOp {
convertFn := genConvertFunc(gFunc, meta, doc, sai, fn)
data.APIs[apiName].ConvertFuncs = append(data.APIs[apiName].ConvertFuncs, convertFn)
}
Expand All @@ -153,8 +153,12 @@ func genConvertFunc(genFunc *GenFunc, meta *saiast.FuncMetadata, info *docparser
ProtoResponseType: genFunc.ProtoResponseType,
}
paramDefs, paramVars := getParamDefs(sai.Funcs[fn.Typ].Params)
convertFn.Args = strings.Join(paramDefs[1:], ", ")
convertFn.Vars = strings.Join(paramVars[1:], ", ")
startIdx := 1
if genFunc.Operation == flushOp {
startIdx = 0
}
convertFn.Args = strings.Join(paramDefs[startIdx:], ", ")
convertFn.Vars = strings.Join(paramVars[startIdx:], ", ")
convertFn.AttrSwitch = &AttrSwitch{
Var: "attr_list[i].id",
ProtoVar: "msg",
Expand Down Expand Up @@ -249,6 +253,8 @@ func populateCCInfo(meta *saiast.FuncMetadata, apiName string, sai *saiast.SAIAP
}

switch genFunc.Operation {
case flushOp:
genFunc.ConvertFunc = strcase.SnakeCase("convert_" + meta.Name)
case createOp:
genFunc.ConvertFunc = strcase.SnakeCase("convert_create " + meta.TypeName)
case getAttrOp:
Expand Down Expand Up @@ -359,6 +365,7 @@ const (
createOp = "create"
getAttrOp = "get_attribute"
setAttrOp = "set_attribute"
flushOp = "flush"
)

type accessorType int
Expand Down Expand Up @@ -637,6 +644,18 @@ func genProtoReqResp(docInfo *docparser.SAIInfo, apiName string, meta *saiast.Fu

// Handle proto generation
switch meta.Operation {
case flushOp:
req.Fields = append(req.Fields, protoTmplField{
Index: 1,
ProtoType: "uint64",
Name: "switch",
})
attrs, err := CreateAttrs(2, meta.TypeName, docInfo, docInfo.Attrs[meta.TypeName].CreateFields)
if err != nil {
return nil, nil, err
}
req.Fields = append(req.Fields, attrs...)
req.Option = "option (sai_type) = OBJECT_TYPE_UNSPECIFIED"
case createOp:
requestIdx := 1
if meta.IsSwitchScoped {
Expand Down
Loading
Loading